【问题标题】:Running Selenium via NUnit and Cruise Control .NET通过 NUnit 和 Cruise Control .NET 运行 Selenium
【发布时间】:2013-06-17 16:06:30
【问题描述】:

我在通过 Cruise Control .NET 在 NUnit 中运行 Selenium 测试时遇到问题。当我从持续集成服务器上的 NUnit GUI 运行时,我有一个简单的测试运行良好。但是,当 NUnit 测试从同一服务器上的 Cruise Control .NET 运行时,测试总是失败。不使用 Selenium 的测试可以在 NUnit GUI 和 Cruise Control 中正常运行。

[SetUp]
    public void SetupTest()
    {
        Driver = new InternetExplorerDriver();
    }



    [TearDown]
    public void TeardownTest()
    {
        Driver.Quit();
    }



    /// <summary>
    /// Test basic Selenium functionality.
    /// </summary>
    [Test]
    public void SeleniumTest()
    {
        Driver.Navigate().GoToUrl(TestConfig.TestURL);
        IWebElement testEle = WaitForElement(Driver, By.Id, "body", TestConfig.TestWaitMS);
        Assert.IsTrue(true);
    }



    private static IWebElement WaitForElement(IWebDriver driver, ByFunc byFunc, string elementId, int waitMs,
        string waitOutput = null, int pause = 50)
    {
        bool elementFound = false;
        int i = 0;
        IWebElement webElement = null;
        while (!elementFound && (i * pause) < waitMs)
        {
        try
        {
            webElement = driver.FindElement(byFunc(elementId));
            elementFound = true;
        }
        catch (NoSuchElementException)
        {
            i++;
            Thread.Sleep(pause);
            if (waitOutput != null)
            Console.Write(waitOutput);
        }
        }
        if (elementFound)
        return webElement;
        else
        throw new NoSuchElementException(string.Format("Could not find element {0} after waiting {1}ms.", elementId, waitMs));
    }

WaitForElement 只是一个辅助函数,它允许我为某些元素分配特定的等待时间,而不是为整个测试运行设置一揽子等待时间。

当从 WaitForElement 函数引发 NoSuchElementException 时,测试失败。

我在 Google 上找到了一些链接,说您需要将 SeleniumRC 作为服务运行才能从 Cruise Control 中运行。我认为这不适用于这里,因为我使用的是 WebDriver 版本。如果我错了,请纠正我。

  1. IE 版本 8
  2. 巡航控制 .NET 1.8.3.0
  3. NUnit 2.6
  4. 硒 2.0.0

【问题讨论】:

  • 其他驱动程序也会发生这种情况吗?具体是什么版本的 Selenium? (目前是v2.33) IEDriver 是什么版本?您的WaitForElement 代码只是库中已有代码的重复代码,特别是WebDriverWait。您是否真的尝试过在服务帐户下运行它?有什么不同吗?
  • @Arran 感谢您的建议。我今天就试试看。
  • @Arran 切换到 Firefox 解决了这个问题,所以我猜问题出在 Internet Explorer 驱动程序的某个地方。
  • 这很好,虽然这是一种解决方法 - 是否有任何特殊需要拥有 IEDriver? (我指出尝试其他驱动程序只是为了查看问题是否存在于 IE/IEDriver 或您的代码中)您是否设置了保护模式设置? code.google.com/p/selenium/wiki/InternetExplorerDriver
  • @Arran 绝对是一种解决方法。我在 Windows Server 2003 版本的 IE8 中找不到保护模式设置。如果我有时间回到这里,我会更新。

标签: nunit selenium-webdriver cruisecontrol.net


【解决方案1】:

感谢@Arran 的指点。切换到 Firefox 驱动程序解决了这个问题。我想问题一定出在 Internet Explorer 驱动程序的某个地方。

[SetUp]
public void SetupTest()
{
    Driver = new FirefoxDriver();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-06
    • 2014-03-09
    • 1970-01-01
    • 2010-12-03
    • 2013-03-09
    • 1970-01-01
    相关资源
    最近更新 更多