1

I have a selenium test that performs a repeated set of actions on an application, to test exactly what happens when the same thing is done many many times. This is done with an infinite loop, because I don't actually need a pass/fail, I just need to see if it's still there in 2/4/8/24/48 hours. The problem I'm having is that something causes my browser to die during the night.

Driver info: driver.version: RemoteWebDriver
[junit]     at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:493)
[junit]     at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:244)
[junit]     at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:77)
[junit]     at wl12cStartServers.<method1>(<testname>.java:66)
[junit]     at wl12cStartServers.<method2>(<testname>.java:34)
[junit] Caused by: java.net.SocketTimeoutException: Read timed out

This is the same error as would appear if i were to kill the browser window started by selenium, But I have no idea what is causing it to die in this instance.. I have seen the script run for several hours when I'm watching it..

4

1 回答 1

0

正如用户 KPZ 所建议的,问题可能出在测试期间计算机进入睡眠模式(或任何类似模式)。试试这个对策:

private static Timer screenSaverDisabler;

/** Moves mouse once in a minute and therefore prevents the screen saver from kicking in. */
private static void disableScreenSaver() {
    screenSaverDisabler = new Timer();
    screenSaverDisabler.scheduleAtFixedRate(new TimerTask() {
        Robot r = null;
        // initialization block
        {
            try {
                r = new Robot();
            } catch (AWTException headlessEnvironmentException) {
                screenSaverDisabler.cancel();
            }
        }
        @Override
        public void run() {
            Point loc = MouseInfo.getPointerInfo().getLocation();
            r.mouseMove(loc.x + 1, loc.y);
            r.mouseMove(loc.x, loc.y);
        }
    }, 0, 59*1000);
}

另外,完成后不要忘记打电话screenSaverDisabler.cancel();


如果这没有帮助,我不知道是什么导致了问题。如果你不知道,有一个明显的解决方案:

这是一个可恢复的异常!在你的主循环中添加一个try-catch块来捕捉这个问题(捕捉任何RemoteWebdriverException并过滤掉那些不是由 引起的SocketTimeoutException)并重新启动浏览器。

于 2013-04-29T10:02:51.100 回答