通过NUnit和巡航控制.NET运行Selenium
我在巡航控制.NET上运行NUnit中的Selenium测试时遇到问题。我有一个简单的测试,当我在我们的持续集成服务器上从NUnitGUI运行时,它运行良好。但是,当NUnit测试在同一台服务器上从Cruise Control.NET运行时,测试总是失败。不使用Selenium的测试可以从NUnit GUI和巡航控制系统正常运行通过NUnit和巡航控制.NET运行Selenium,nunit,selenium-webdriver,cruisecontrol.net,Nunit,Selenium Webdriver,Cruisecontrol.net,我在巡航控制.NET上运行NUnit中的Selenium测试时遇到问题。我有一个简单的测试,当我在我们的持续集成服务器上从NUnitGUI运行时,它运行良好。但是,当NUnit测试在同一台服务器上从Cruise Control.NET运行时,测试总是失败。不使用Selenium的测试可以从NUnit GUI和巡航控制系统正常运行 [SetUp] public void SetupTest() { Driver = new InternetExplorerDrive
[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));
}
[设置]
公共测试()
{
驱动程序=新的InternetExplorerDriver();
}
[撕裂]
公共无效删除测试()
{
Driver.Quit();
}
///
///测试基本的Selenium功能。
///
[测试]
公共无效硒测试()
{
Driver.Navigate().gotour(TestConfig.TestURL);
IWebElement testEle=WaitForElement(驱动程序,By.Id,“body”,TestConfig.TestWaitMS);
Assert.IsTrue(真);
}
私有静态IWebElement WaitForElement(IWebDriver驱动程序、ByFunc ByFunc、string elementId、int waitMs、,
字符串waitOutput=null,int pause=50)
{
bool elementFound=false;
int i=0;
IWebElement webElement=null;
而(!elementFound&(i*pause)
WaitForElement只是一个帮助函数,它允许我为某些元素分配特定的等待时间,而不是为整个测试运行分配一个总的等待时间
当从WaitForElement函数引发NoTouchElementException时,测试失败
我在谷歌上找到了一些链接,说你需要运行SeleniumRC作为一项服务,才能从巡航控制系统运行它。我认为这不适用于这里,因为我使用的是WebDriver版本。如果我错了,请纠正我
谢谢你的指点@Arran。切换到Firefox驱动程序解决了这个问题。我想故障一定出在Internet Explorer驱动程序的某个地方
[SetUp]
public void SetupTest()
{
Driver = new FirefoxDriver();
}
其他司机也会这样吗?硒的具体版本是什么?(当前版本为v2.33)IEDriver的哪个版本?您的
WaitForElement
代码只是库中已有内容的重复代码,特别是WebDriverWait
。你真的试过用服务帐户运行它吗?这有什么不同吗?@Arran谢谢你的建议。我今天要试一试。@Arran切换到Firefox解决了这个问题,所以我猜问题出在internet explorer驱动程序的某个地方。这很好,尽管这是一个解决方法-是否有特殊需要使用IEDriver?(我指出尝试其他驱动程序只是为了看看IE/IEDriver或您的代码中是否存在问题)您是否设置了保护模式设置@阿伦肯定是个解决办法。在IE8的Windows Server 2003版本中找不到受保护模式设置。如果有时间,我会更新的。