我正在努力修复Selenium测试的问题,这些测试旨在测试在网站上的多个类别中提交评论,并且我在执行请求时遇到连接丢失的问题。错误似乎是不确定的 - 它们不会一直发生,并且在给定操作的设置超时之前发生。我在CentOS虚拟机(在我的本地计算机上)上运行Selenium集线器,这似乎不太可能导致网络问题,因为网络服务器也在我的机器上本地运行。我遇到了两个主要的例外:"与远程浏览器通信时出错。它可能已经死了。"和CLIENT_GONE。我在下面列出了每个样本。如果我运行测试50次,他们可能会在10-30%的任何时间失败,而其余的时间他们运行没有问题。我是否遗漏了与虚拟盒连接有关的内容,或者我如何使用Selenium?提前致谢。
UnreachableBrowserException的堆栈跟踪:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.5.0-49-generic', java.version: '1.7.0_60'
Driver info: driver.version: CoreDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
at org.openqa.selenium.remote.RemoteWebDriver.getPageSource(RemoteWebDriver.java:414)
at org.openqa.selenium.remote.Augmenter$CompoundHandler.intercept(Augmenter.java:280)
at org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB$$58bad765.getPageSource(<generated>)
at com.foo.selenium.CoreDriver.captureScreenAndSource(CoreDriver.java:537)
at com.foo.selenium.CoreDriver.captureScreenAndSource(CoreDriver.java:513)
at com.foo.selenium.CoreDriver.captureScreenAndSource(CoreDriver.java:497)
at com.foo.selenium.CoreDriver.waitForElementToAppearInElementByLocator(CoreDriver.java:378)
at com.foo.selenium.CoreDriver.waitForElementToAppearInElementByLocator(CoreDriver.java:343)
at com.foo.bar.reviewtest.ResponseTest.verifyResponse(ResponseTest.java:121)
at com.foo.bar.reviewtest.ResponseTest.runATest(ResponseTest.java:48)
at com.foo.bar.reviewtest.UserTestBase.testDriver(UserTestBase.java:129)
Caused by: org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 1207803; received: 0
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:184)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:204)
at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:108)
at org.apache.http.conn.BasicManagedEntity.streamClosed(BasicManagedEntity.java:157)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:237)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:186)
at org.apache.http.util.EntityUtils.consume(EntityUtils.java:85)
at org.openqa.selenium.remote.HttpCommandExecutor$EntityWithEncoding.<init>(HttpCommandExecutor.java:412)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:300)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 39 more
... Removed 27 stack frames
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.5.0-49-generic', java.version: '1.7.0_60'
Driver info: driver.version: CoreDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
at org.openqa.selenium.remote.RemoteWebDriver.getPageSource(RemoteWebDriver.java:414)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.openqa.selenium.remote.Augmenter$CompoundHandler.intercept(Augmenter.java:280)
at org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB$$58bad765.getPageSource(<generated>)
at com.foo.selenium.CoreDriver.captureScreenAndSource(CoreDriver.java:537)
at com.foo.selenium.CoreDriver.captureScreenAndSource(CoreDriver.java:513)
at com.foo.selenium.CoreDriver.captureScreenAndSource(CoreDriver.java:497)
at com.foo.selenium.CoreDriver.waitForElementToAppearInElementByLocator(CoreDriver.java:378)
at com.foo.selenium.CoreDriver.waitForElementToAppearInElementByLocator(CoreDriver.java:343)
at com.foo.bar.reviewtest.ResponseTest.verifyResponse(ResponseTest.java:121)
at com.foo.bar.reviewtest.ResponseTest.runATest(ResponseTest.java:48)
at com.foo.bar.reviewtest.UserTestBase.testDriver(UserTestBase.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.TestNG.privateMain(TestNG.java:1338)
at org.testng.TestNG.main(TestNG.java:1307)
Caused by: org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 1207803; received: 0
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:184)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:204)
at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:108)
at org.apache.http.conn.BasicManagedEntity.streamClosed(BasicManagedEntity.java:157)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:237)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:186)
at org.apache.http.util.EntityUtils.consume(EntityUtils.java:85)
at org.openqa.selenium.remote.HttpCommandExecutor$EntityWithEncoding.<init>(HttpCommandExecutor.java:412)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:300)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 39 more
第二个错误:
org.openqa.selenium.WebDriverException: Session [fa85a873-517b-4054-8690-cccc02e17f41] was terminated due to CLIENT_GONE
Command duration or timeout: 2.56 seconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.5.0-49-generic', java.version: '1.7.0_60'
Session ID: fa85a873-517b-4054-8690-cccc02e17f41
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{platform=LINUX, chrome.chromedriverVersion=26.0.1383.0, acceptSslCerts=false, javascriptEnabled=true, browserName=chrome, rotatable=false, locationContextEnabled=false, webdriver.remote.sessionid=fa85a873-517b-4054-8690-cccc02e17f41, version=26.0.1410.63, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:348)
at org.openqa.selenium.By$ById.findElement(By.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at org.openqa.selenium.remote.Augmenter$CompoundHandler.intercept(Augmenter.java:280)
at org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByCGLIB$$29d6fa2e.findElement(<generated>)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:523)
at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:521)
at org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:289)
at org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at com.tools.selenium.CoreDriver.waitForElementToBeInvisible(CoreDriver.java:300)
at com.tools.selenium.CoreDriver.waitForElementToBeInvisible(CoreDriver.java:288)
at com.foo.bar.reviewtest.ResponseTest.loginOnVisit(ResponseTest.java:55)
at com.foo.bar.reviewtest.ResponseTest.runATest(ResponseTest.java:44)
at com.foo.bar.reviewtest.UserTestBase.testDriver(UserTestBase.java:129)
Caused by: org.openqa.grid.common.exception.GridException: Session [fa85a873-517b-4054-8690-cccc02e17f41] was terminated due to CLIENT_GONE
at org.openqa.grid.internal.ActiveTestSessions.getExistingSession(ActiveTestSessions.java:104)
at org.openqa.grid.internal.Registry.getExistingSession(Registry.java:423)
at org.openqa.grid.web.servlet.handler.RequestHandler.getSession(RequestHandler.java:234)
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:116)
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:84)
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.seleniumhq.jetty7.servlet.ServletHolder.handle(ServletHolder.java:565)
at org.seleniumhq.jetty7.servlet.ServletHandler.doHandle(ServletHandler.java:479)
at org.seleniumhq.jetty7.server.session.SessionHandler.doHandle(SessionHandler.java:225)
at org.seleniumhq.jetty7.server.handler.ContextHandler.doHandle(ContextHandler.java:1031)
at org.seleniumhq.jetty7.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.seleniumhq.jetty7.server.session.SessionHandler.doScope(SessionHandler.java:186)
at org.seleniumhq.jetty7.server.handler.ContextHandler.doScope(ContextHandler.java:965)
at org.seleniumhq.jetty7.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.seleniumhq.jetty7.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
at org.seleniumhq.jetty7.server.Server.handle(Server.java:349)
at org.seleniumhq.jetty7.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:452)
at org.seleniumhq.jetty7.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:47)
at org.seleniumhq.jetty7.server.AbstractHttpConnection.content(AbstractHttpConnection.java:894)
at org.seleniumhq.jetty7.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:948)
at org.seleniumhq.jetty7.http.HttpParser.parseNext(HttpParser.java:857)
at org.seleniumhq.jetty7.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.seleniumhq.jetty7.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:66)
at org.seleniumhq.jetty7.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:254)
at org.seleniumhq.jetty7.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599)
at org.seleniumhq.jetty7.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534)
at java.lang.Thread.run(Thread.java:722)
... Removed 30 stack frames
答案 0 :(得分:-1)
你有没有遇到过这个问题?我经常看到第二个问题(CLIENT_GONE)。
我们经常在一夜之间进行一系列Selenium测试(大约200次),并且在过去的两个晚上已经有数百个这样的实例。
大约96%的错误来自 get_PageSource
绝大多数人也花费超过25分钟来产生此错误,因此看起来可能是超时问题。