0

我有一组相当大的 Selenium 测试(大约 180 个),它们在 XP 和 Win7 32/64 位机器上运行得非常好。

最近,在 Windows 7 更新后(可能是巧合),测试变得不可靠。它们随机失败,但总是出现相同的问题 - 显示预期的屏幕,但 WaitForPageToLoad() 方法没有返回以确认这一点。这不会发生在 XP 机器上,只会出现在最近更新的 Win7 机器上。

平台:Win7、32 和 64 位、Selenium 1.0 和 2.33.0(行为无差异)、VS2008、浏览器 IE9。

场景:测试最初显示一个带有单个按钮的“重新启动”屏幕,单击应该启动登录屏幕的按钮(所有测试都通过相同的代码来执行此操作)。登录屏幕显示在浏览器中但测试线

selenium.WaitForScreenToDisplay(30000);

不返回,因此测试超时并显示错误消息。测试将以这种方式完全随机失败 - 其中大约一半失败,但并非始终相同。

当人类与浏览器交互时,应用程序本身的行为非常完美。selenium 日志并没有提供太多线索 - 最后一行始终是“等待页面”,例如“....命令请求:waitForPageToLoad[30000,...]”。

在 VS 调试器中单步执行测试永远不会重现问题。

问题表现出来的实际代码是

    selenium.Open(GetRestartPageURL());
    selenium.WaitForPageToLoad("30000");

    selenium.Click("Button");
    selenium.WaitForPageToLoad("30000"); <-- this is where it times out even though the expected screen that is launched by "Button" is now displayed in the browser

是否存在已知问题或解决方法?这是 IE9 和 Selenium 1.0 的问题吗?它在关键时刻突然出现。

4

1 回答 1

1

这被证明是 IE9/10 和/或 selenium 中的一个错误,或者至少是 IE9/10 中的一个错误,selenium 的人看起来不会很快解决。我通过编写自己的 WaitForPage 方法来解决它,该方法在浏览器中查看 window.document.readyState 并监视延迟,因此我仍然有超时。

这是代码,如果它可以帮助其他人:

internal static void WaitForPageToLoad(ISelenium selenium)
{
    //Wait until the browser reports that it is no longer loading the page, or 'timeOut' has been reached.
    //Pause 1/4 second between attempts (should normally be sufficient for the page to load, unless it is a very slow page)
    const int timeOut = 30000; //mS
    const int pause = 250;     //mS

    int timeWaited = 0;

    do
    {
        System.Threading.Thread.Sleep(pause);
        timeWaited += pause;
    }
    while (selenium.GetEval("window.document.readyState") != "complete" && timeWaited<timeOut);

    if (timeWaited >= timeOut)
    {
        //abort test and notify error:
        Assert.Fail("Expected page was not dislpayed");
    }
}

Selenium 错误跟踪器中有两个引用此错误的问题:16392451

于 2013-06-14T08:43:01.613 回答