有时webDriver.quit()方法会在没有消息的情况下提供异常。但它成功地关闭了浏览器。它只发生在网格上,我无法在本地机器上重现这一点。它可能与并行执行有关,我不知道。异常似乎是随机的,这让我发疯到不知道。
在测试结束时,我的代码块是;
public void close() {
try {
webDriver.quit();
} catch (Exception ex) {
logger.error("Exception on closing webdriver", ex);
}
}
错误日志是:
2016-04-17 20:18:02,169 ERROR [pool-1-thread-1] models.Browser - Exception on ?closing webdriver
org.openqa.selenium.WebDriverException: Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'taylanderinbay.local', ip: '172.20.0.196', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.4', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=45.0.2, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webdriver.remote.sessionid=e64115cd-ba83-4e01-89b8-e5b16e7a4e0f, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e64115cd-ba83-4e01-89b8-e5b16e7a4e0f
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_77]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_77]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_77]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_77]
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) ~[selenium-remote-driver-2.53.0.jar:?]
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) ~[selenium-remote-driver-2.53.0.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) ~[selenium-remote-driver-2.53.0.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:701) ~[selenium-remote-driver-2.53.0.jar:?]
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:526) ~[selenium-remote-driver-2.53.0.jar:?]
at com.dmall.uat.models.Browser.close(Browser.java:228) [classes/:?]
at com.dmall.uat.models.users.Visitor.closeBrowser(Visitor.java:214) [classes/:?]
at com.dmall.uat.test.TestContext.closeBrowsers(TestContext.java:48) [classes/:?]
at com.dmall.uat.test.StopOrCloseFixtures$1.evaluate(StopOrCloseFixtures.java:30) [classes/:?]
at com.dmall.uat.test.FreeUser$1.evaluate(FreeUser.java:23) [classes/:?]
at com.dmall.uat.test.FreeAccount$1.evaluate(FreeAccount.java:23) [classes/:?]
at com.dmall.uat.test.FailedTestRetry$1.evaluate(FailedTestRetry.java:29) [classes/:?]
at com.dmall.uat.test.TestContextInitializer$1.evaluate(TestContextInitializer.java:24) [classes/:?]
at org.junit.rules.RunRules.evaluate(RunRules.java:20) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) [junit-4.12.jar:4.12]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
at org.apache.maven.surefire.junitcore.pc.Scheduler$1.run(Scheduler.java:387) [surefire-junit47-2.18.1.jar:2.18.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_77]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_77]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_77]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_77]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'taylanderinbay.local', ip: '172.20.0.196', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.4', java.version: '1.8.0_77'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:138) ~[selenium-remote-driver-2.53.0.jar:?]
... 22 more
Caused by: java.lang.InterruptedException
at java.lang.ProcessImpl.waitFor(Unknown Source) ~[?:1.8.0_77]
at org.openqa.selenium.os.ProcessUtils$ProcessWaiter.run(ProcessUtils.java:164) ~[selenium-remote-driver-2.53.0.jar:?]
at java.lang.Thread.run(Unknown Source) ~[?:1.8.0_77]
我非常感谢任何帮助或建议。感谢
答案 0 :(得分:0)
似乎有时当你退出驱动程序时,你正在打断屏幕截图。也许完成一些IO。
在网格上运行时,您是否获得了预期的屏幕截图? 尝试在驱动程序功能中设置takeScreenshot = false并查看是否继续发生。