Cruise Control .NET から NUnit で Selenium テストを実行する際に問題が発生しています。継続的インテグレーション サーバーの NUnit GUI から実行すると問題なく実行される簡単なテストがあります。ただし、同じサーバー上の Cruise Control .NET から NUnit テストを実行すると、テストは常に失敗します。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 が発生すると、テストは失敗します。
Cruise Control から SeleniumRC を実行するには、SeleniumRC をサービスとして実行する必要があるというリンクが Google で見つかりました。私は WebDriver バージョンを使用しているので、ここでは当てはまらないと思います。私が間違っている場合は、私を修正してください。
- バージョン 8
- クルーズ コントロール .NET 1.8.3.0
- NUnit 2.6
- セレン 2.0.0