我每小时使用selenium-java 3.12.0运行一堆测试用例; TestNG; Selenoid和Docker,Jenkins。 有时(大约每10个案例中就有1个)我得到了错误:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'autotest.rvkernel.com', ip: '94.130.165.217', os.name: 'Linux', os.arch: 'amd64', os.version: '4.13.0-26-generic', java.version: '1.8.0_181'
Driver info: driver.version: RemoteWebDriver
Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=LINUX, acceptSslCerts=false, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=LINUX, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.39.562737 (dba483cee6a5f15e2e2d73df16968ab10b38a2bf), userDataDir=/tmp/.org.chromium.Chromium.gURWcu}, takesHeapSnapshot=true, pageLoadStrategy=normal, unhandledPromptBehavior=, databaseEnabled=false, handlesAlerts=true, version=67.0.3396.62, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
Session ID: 56c4b100a95d89b3d5702ec8a1a0698a
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:564)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:376)
at com.sun.proxy.$Proxy14.click(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:389)
at com.Elements.Element.lambda$click$2(Element.java:99)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at com.Elements.Element.click(Element.java:98)
at com.Elements.Element.click(Element.java:78)
at com.pages.landing.social.MailRuRegisterPage.clickRegister(MailRuRegisterPage.java:37)
at RulVulaknTests.authorization.AuthorizationTest.authorizationUserFromMailRU(AuthorizationTest.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: Cannot decode response content:
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:83)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
... 28 more
Caused by: org.openqa.selenium.json.JsonException: java.io.EOFException: End of input at line 1 column 1 path $
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'autotest.rvkernel.com', ip: '94.130.165.217', os.name: 'Linux', os.arch: 'amd64', os.version: '4.13.0-26-generic', java.version: '1.8.0_181'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.json.JsonInput.execute(JsonInput.java:172)
at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:72)
at org.openqa.selenium.json.JsonTypeCoercer.lambda$null$6(JsonTypeCoercer.java:136)
at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:122)
at org.openqa.selenium.json.Json.toType(Json.java:62)
at org.openqa.selenium.json.Json.toType(Json.java:52)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
... 31 more
Caused by: java.io.EOFException: End of input at line 1 column 1 path $
at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1401)
at com.google.gson.stream.JsonReader.consumeNonExecutePrefix(JsonReader.java:1576)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:534)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:425)
at org.openqa.selenium.json.JsonInput.lambda$peek$0(JsonInput.java:73)
at org.openqa.selenium.json.JsonInput.execute(JsonInput.java:168)
... 37 more
在此错误之后,所有剩余的测试都将被跳过。
我在使用Chrome浏览器的版本中遇到了错误-66、67。
答案 0 :(得分:0)
此错误消息...
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
...表示 RemoteWebDriver 实例突然关闭。
您的代码试用会对调试问题有所帮助。也许您的主要问题可能是以下问题之一:
按照最佳做法:
您已经提到每小时运行一堆测试用例 ,可能有多个 ChromeDriver 和 Chrome 悬空的实例可以通过进程列表(Linux OS)或 TaskManager (Windows OS)查看。您需要始终在driver.quit()
方法内调用tearDown(){}
来优雅地关闭和销毁 WebDriver 和 Web Client 实例。
如果 WebDriver 和 Web浏览器的悬空实例仍然存在,请考虑使用蛮力杀死它们。您可以在Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
如果您的程序尝试从大于5000的端口建立TCP连接,则可以参考此article
参考文献