将Driver声明为WebDriver后调用ExecuteCdpCommand方法编译报错的解决方案求助
将Driver声明为WebDriver后调用ExecuteCdpCommand方法编译报错的解决方案求助
我们有一套用Visual Studio/C#和Selenium编写的、在Chrome上运行的回归测试套件。
启动代码的一部分如下:
protected static ChromeDriver? Driver { get; set; } = null; Driver = new ChromeDriver(service, options, TimeSpan.FromSeconds(MaxWait)); Driver.ExecuteCdpCommand( "Emulation.setTimezoneOverride", new Dictionary<string, object> { ["timezoneId"] = "Europe/London" });
这段ExecuteCdpCommand代码是为了确保在Azure Pipeline执行测试时,某些测试能在英国时区运行,之前一直工作得很好。但现在我们打算隔天轮流在Chrome和Edge上运行夜间回归测试——比如第一天Chrome,第二天Edge,再回到Chrome这样。现在除了ExecuteCdpCommand这部分,其他一切都正常运行。
现在我们把Driver的声明改成了这样:
protected static WebDriver? Driver { get; set; } = null; Driver = new ChromeDriver(service, options, TimeSpan.FromSeconds(MaxWait)); // 或者根据星期几换成下面的代码 Driver = new EdgeDriver(service, options, TimeSpan.FromSeconds(MaxWait));
结果出现了如下编译错误:
'WebDriver' does not contain a definition for 'ExecuteCdpCommand' and no accessible extension method 'ExecuteCdpCommand' accepting a first argument of type 'WebDriver' could be found (are you missing a using directive or an assembly reference?)

这实在让人头疼,因为除了这个问题,我们的测试已经准备就绪了。有没有人能帮忙解决这个小问题呢?
备注:内容来源于stack exchange,提问作者Kev
相关产品推荐
相关产品推荐

