【问题标题】:Selenium does not see a screen is present - introduced after Windows updateSelenium 看不到屏幕存在 - Windows 更新后引入
【发布时间】:2013-06-12 14:30:45
【问题描述】:

我有相当多的 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 的问题吗?它在关键时刻突然出现。

【问题讨论】:

  • 你是否增加了超时时间并看到测试仍然失败?

标签: selenium internet-explorer-9 automated-tests selenium-rc


【解决方案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-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    相关资源
    最近更新 更多