0

我在从 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. 浏览器版本 8
  2. 巡航控制 .NET 1.8.3.0
  3. NUnit 2.6
  4. 硒 2.0.0
4

1 回答 1

0

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

[SetUp]
public void SetupTest()
{
    Driver = new FirefoxDriver();
}
于 2013-06-18T08:31:55.160 回答