我在NUnit中运行Control .NET中的Selenium测试时遇到了问题,在我们的连续集成服务器上从NUnit GUI运行时,有一个简单的测试运行良好。但是,当NUnit测试从同一服务器上的Control .NET运行时,测试总是失败。不使用Selenium的测试可以从NUnit GUI和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只是一个帮助函数,它允许我为某些元素分配特定的等待时间,而不是让整个测试运行有一个完整的等待时间。
当从NoSuchElementException函数引发WaitForElement时,测试失败。
我在谷歌上找到了一些链接,上面说你需要将SeleniumRC作为一个服务来运行,让它从Control运行。我不认为这适用于这里,因为我使用的是WebDriver版本。如果我错了,请纠正我。
发布于 2013-06-18 00:31:55
谢谢指点@Arran。切换到Firefox驱动程序解决了这个问题。我想这一定是I驱动程序的错误所在。
[SetUp]
public void SetupTest()
{
Driver = new FirefoxDriver();
}
https://stackoverflow.com/questions/17152015
复制相似问题