首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >通过NUnit和Cruise控件.NET运行Selenium

通过NUnit和Cruise控件.NET运行Selenium
EN

Stack Overflow用户
提问于 2013-06-17 16:06:30
回答 1查看 753关注 0票数 0

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

代码语言:javascript
代码运行次数:0
运行
复制
[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只是一个帮助函数,它允许我为某些元素分配特定的等待时间,而不是让整个测试运行有一个完整的等待时间。

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

我在谷歌上找到了一些链接,上面说你需要将SeleniumRC作为一个服务来运行,让它从Control运行。我不认为这适用于这里,因为我使用的是WebDriver版本。如果我错了,请纠正我。

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

回答 1

Stack Overflow用户

发布于 2013-06-18 08:31:55

谢谢指点@Arran。切换到Firefox驱动程序解决了这个问题。我想这一定是I驱动程序的错误所在。

代码语言:javascript
代码运行次数:0
运行
复制
[SetUp]
public void SetupTest()
{
    Driver = new FirefoxDriver();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17152015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档