将 Selenium 测试与 tfs 集成

Integrating Selenium tests with tfs

所以我已经将我的 NUnit Seleniumt 测试放到了我们团队的 tfs 上。我已将它们配置为构建和 运行 作为 Visual Studio 测试。我已将我的 VsoAgent 配置为交互式。我的测试开始 运行,但在打开 Chrome 后,我看到一条消息,提示 Chrome 自动化扩展已停止工作,我收到错误消息:

OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:54836/session timed out after 60 seconds.
----> System.Net.WebException : The operation has timed out
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
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 SeleniumBase.Selenium_base.setUp(Browsers browser, String URL, Int32 waitMillis) in C:\TFS\agent3\_work\s\PentaJPKSelenium\Selenium_base.cs:line 38
at PentaJPKBase.PentaJPK_base.SetupTest() in C:\TFS\agent3\_work\s\PentaJPKSelenium\PentaJPKSelenium_base.cs:line 17
--WebException
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
--TearDown
at PentaJPKBase.PentaJPK_base.TeardownTest() in C:\TFS\agent3\_work\s\PentaJPKSelenium\PentaJPKSelenium_base.cs:line 54Error: Exception NUnit.Core.UnsupportedFrameworkException, Exception thrown executing tests in C:\TFS\agent3\_work\s\PentaJPKSelenium\bin\Debug\PentaJPKSelenium.dll

当我 运行 在本地而不是通过代理时,一切正常。 有谁知道如何解决这个问题?

尝试使用以下方法缩小问题范围:

  • 更改默认值(60 秒)driver 超时,在 driver 中设置更多时间 构造函数

  • 将您的 Driver 更改为 Firefox Driver

  • 正在升级您的 Selenium Webdriver Nuget 包到最新版本

  • 在构建代理上禁用防火墙。

也看看类似的问题Selenium WebDriver throws Timeout exceptions sporadically & OpenQA.Selenium.WebDriverException : No response from server for url

经过数小时的寻找,我找到了解决方案。我想让 ChromeDriver 在最新版本上工作,Chrome 在最新版本上工作。让它发挥作用的魔法线是:

ChromeOptions options = new ChromeOptions();
options.AddArguments("no-sandbox"); <--------------------------
driver = new ChromeDriver(options);

此行阻止了 Chrome驱动程序尝试以 SYSTEM 用户身份打开 Chrome,他无法使用 VSO 代理处理。