在Visual Studio Team Services(VS Online)上运行测试时ChromeDriver和OperaDriver失败

时间:2016-08-11 16:05:02

标签: selenium selenium-webdriver msbuild azure-devops selenium-chromedriver

我们在团队服务(Visual Studio Online)版本中使用MSTest来运行我们的Selenium测试。 FirefoxDriverInternetExplorerDriver正常运行,但ChromeDriverOperaDriver每次都失败,甚至无法打开浏览器。 它们每次都使用以下堆栈跟踪失败:

Initialization method WebUnitTests.Tests.DatacenterTests.TestInitialize threw exception. OpenQA.Selenium.WebDriverException:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:1410/session timed out after 60 seconds. ---> 
System.Net.WebException: The operation has timed out.

at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
at WebUnitTests.Framework.Utilities.Driver.StartBrowser(BrowserTypes browserType, Int32 defaultTimeOut) in C:\agent2\_work\1\s\WebUnitTests\Framework\Utilities\Driver.cs:line 37
at WebUnitTests.Framework.Utilities.BaseTests.InitializeBrowser(TestContext testContext) in C:\agent2\_work\1\s\WebUnitTests\Framework\Utilities\BaseTests.cs:line 328
at WebUnitTests.Framework.Utilities.BaseTests.TestInitialize() in C:\agent2\_work\1\s\WebUnitTests\Framework\Utilities\BaseTests.cs:line 147

我用来启动驱动程序:

var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--ignore-certificate-errors");
var chromeBrowser = new ChromeDriver(chromeOptions);

要提到的一件非常重要的事情是,如果我在本地计算机上运行测试,一切正常,只有当他们在CI中运行时才会出现问题。

我可以尝试找到根本问题的任何想法?有任何解决方法吗?

1 个答案:

答案 0 :(得分:2)

好吧,看起来这个问题有点复杂,但我发布这个以防有人处于相同的情况。

基本上,测试代理作为服务安装,从Windows(NT)服务启动的每个进程都在会话0上运行,对于已登录的用户是不可见的。

Chrome正试图离开会话0,你可以在这里找到更多的参考资料(下面链接中的注释21,但实际上整个帖子对于这个主题是一个很好的阅读): https://bugs.chromium.org/p/chromium/issues/detail?id=615396#c21

现在,为了解决这个问题,有几个选项: 从Chrome下载Canary版本,但不建议这样做,因为这只是一个临时修复。 Chrome开发人员表示,在不久的将来,Chrome(和ChromeDriver)将无法再使用Session 0。

最佳解决方案是将MS Test Agent安装为进程,以便所有应用程序对登录用户可见。更多详情可在这找到: https://msdn.microsoft.com/en-us/library/ee291332.aspx

另一种选择是将下面的设置添加为Chrome参数,但我没有使用测试代理作为Windows服务进行测试,因此我不知道它是否正常工作,但我可以确认它与测试代理一起作为一个过程。

kadira:flow-router