0

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 バージョンを使用しているので、ここでは当てはまらないと思います。私が間違っている場合は、私を修正してください。

  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 に答える