Selenium 与团队服务的持续集成

Selenium Continuous Integration with Team Services

我的解决方案中的一个测试项目中有一组 Selenium 测试,它们 运行 在 Visual Studio 中很好。但是,当我签入代码并且它们 运行 作为我的持续集成构建配置文件的一部分时,它们失败了。

设置的简要说明: 1) 代码被签入构建代理服务器。

2) 然后构建项目,然后部署到服务器 2(远离构建服务器)。

3) 然后进行单元测试 运行。

这是一个单元测试示例:

public void Login_InvalidAccessUrl_ShowMesage()
{
    driver = new ChromeDriver();
    driver.Manage().Window.Maximize();
    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
    driver.Navigate().GoToUrl("https://testsite.company.com/Login");
    IWebElement el = driver.FindElementById("invalidAccessUrlSection");
    Assert.AreNotEqual(el, null);
}

这个 运行 来自 Visual Studio,但当 CI 运行 进行相同的测试时,我得到以下结果:

Error Message:
Test method eNotify.Staff.Tests.SeleniumTests.Login_InvalidAccessUrl_ShowMesage threw exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:11570/session timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out
TestCleanup method eNotify.Staff.Tests.SeleniumTests.Dispose threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object..
Stack Trace:
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 OpenQA.Selenium.Chrome.ChromeDriver..ctor()
at eNotify.Staff.Tests.SeleniumTests.Login_InvalidAccessUrl_ShowMesage()
TestCleanup Stack Trace
at eNotify.Staff.Tests.SeleniumTests.Dispose()

我是不是缺少驱动程序或某些软件?据我所知,11570端口没有监听。

首先,确保 VSTS 代理 运行 作为交互进程。

其次,为 ChromeDrive 实例添加 no-sanbox 参数。例如:

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