本文介绍了在Visual Studio Team Services(VS Online)上运行测试时,Selenium ChromeDriver和OperaDriver失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我们正在使用  MSTest  使用团队服务(Visual Studio Online)构建以运行我们的Selenium测试。  FirefoxDriver    InternetExplorerDriver  是正确运行,但是  ChromeDriver    OperaDriver  每次都是失败,甚至无法打开浏览器。每次都有以下堆栈跟踪失败: 初始化方法WebUnitTests.Tests.DatacenterTests.TestInitialize抛出异常OpenQA.Selenium.WebDriverException: OpenQA.Selenium.WebDriverException:HTTP请求为URL为http远程服务器的webdriver://本地主机: 1410 /会话在60秒后超时.---> System.Net.WebException:操作已经超时。 在System.Net.HttpWebRequest.GetResponse()$ b在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest的请求) ---内部异常堆栈跟踪的结尾--- 。在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse $ b(的WebRequest请求) 在OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(命令commandToExecute)在OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(命令commandToExecute)在OpenQA.Selenium.Remote.RemoteWebDriver.Execute (String driverCommandToExecute,Dictionary`2参数) at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)在OpenQA.Selenium.Remote.RemoteWebDriver..ctor (ICommandExecutor commandExecutor,ICapabilities desiredCapabilities)在OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions选项)。在WebUnitTests。 Framework.Utilities.Driver.StartBrowser(BrowserTypes browserType,的Int32 defaultTimeOut)在C:\agent2\_work\1\s\WebUnitTests\Framework\Utilities\Driver.cs:线37 在WebUnitTests.Framework.Utilities.BaseTests.InitializeBrowser(的TestContext的TestContext)在C:\agent2\_work\1\s\WebUnitTests\Framework\Utilities\BaseTests.cs:线328 在C:\\\\\\\\\\\\\\ code> 我用来启动驱动程序: var chromeOptions = new ChromeOptions(); chromeOptions.AddArgument(" - ignore-certificate-errors"); var chromeBrowser = new ChromeDriver(chromeOptions); 一个非常重要的事情是,如果我在我的本地机器上运行测试一切正常,问题是它们在CI中运行时。 由于只有在通过CI运行测试时才会发生这种情况,我认为这可能是由构建代理处理此问题引起的问题。 我可以尝试找到根本问题的任何想法?解决这个问题的任何解决方法?解决方案 Hello Cosmin Gramada, 感谢您在此处发帖。 由于这需要调查,我建议您创建包含所有详细信息的支持服务单,团队成员将帮助您解决问题。 https://www.visualstudio.com/en-us/support/support-overview-vs 感谢您的理解。 此致We're using MSTest with Team Services (Visual Studio Online) builds to run our Selenium Tests. FirefoxDriver and InternetExplorerDriver are running correctly, however ChromeDriver and OperaDriver are failing everytime, without even being able to open the browser. They fail everytime with the following stacktrace: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 37at WebUnitTests.Framework.Utilities.BaseTests.InitializeBrowser(TestContext testContext) in C:\agent2\_work\1\s\WebUnitTests\Framework\Utilities\BaseTests.cs:line 328at WebUnitTests.Framework.Utilities.BaseTests.TestInitialize() in C:\agent2\_work\1\s\WebUnitTests\Framework\Utilities\BaseTests.cs:line 147What I'm using to start the driver:var chromeOptions = new ChromeOptions();chromeOptions.AddArgument("--ignore-certificate-errors");var chromeBrowser = new ChromeDriver(chromeOptions);One very important thing to mention is that if I'm running the tests on my local machine everything works fine, the issue is only when they're run in CI.Since this is happening only when the tests are ran through CI, I'm thinking that maybe this is an issue caused by how the build agent is handling this.Any ideas in what I could try to find the root problem? Any workarounds to solve this? 解决方案 Hello Cosmin Gramada,Thank you for posting in here.As this requires an investigation, I would suggest you to create support ticket with all the details, someone from the team will help you to resolve the issue.https://www.visualstudio.com/en-us/support/support-overview-vsThank you for understanding.Regards, 这篇关于在Visual Studio Team Services(VS Online)上运行测试时,Selenium ChromeDriver和OperaDriver失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-25 05:33