Selenium webdriver 连接超时

Selenium webdriver connect timeout

我 运行 在我的 Teamcity 构建服务器上进行 Selenium 测试。但是测试无法开始,出现以下错误消息:

OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:56064/session timed out after 120 seconds. ----> System.Net.WebException : The operation has timed out

测试基地class(缩写):

public abstract class TestBase<T> where T : IWebDriver, new()
{
    protected IWebDriver Driver { get; set; }


    [TestFixtureSetUp]
    public void Setup()
    {
       this.Driver = new T();
    }

    protected void GotoUrl(string url)
    {
        var completeUrl = UrlFactory.Instance.GetTestUrl(url);

        Console.WriteLine("Starting test at " + completeUrl);

        this.Driver.Navigate().GoToUrl(completeUrl);

    }

}

测试class:

[TestFixture(typeof(FirefoxDriver))]
public class Dashboard<T> : TestBase<T> where T : IWebDriver, new()
{
    private const string Url = "RM/Dashboard/dashboard.aspx";

    [Test]
    public void HasCorrectHeading()
    {
        // Arrange         
        this.GotoUrl(Url);

        // Act
        var heading = this.Driver.FindElement(By.CssSelector(".pageheaderContainerxboxcontent span.H1"));

        // Assert
        Assert.That(heading, Is.Not.Null);
    }
}

测试 运行 在本地开发机器上很好,有什么问题吗?

Visual Studio 解法:

全部由 dll:s 引用,而非 Nuget 提要。

文件 'geckodriver.exe' 和 'chromedriver.exe' 复制到 UI-tests 项目 bin-folder 在 post-build 事件中。

运行 Windows Server 2008 R2 SP 1

上的 TeamCity 10

在 GoToURL() 方法之后添加以下行:

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

像往常一样,当您必须准确解释正在发生的事情时,您会遇到一些问题...

我意识到 TeamCity 服务器上的 Firefox 很旧 (v 30),所以我将它更新到最新版本,突然 - 测试 运行! :-)