6

我正在 PhantomJS 1.9.1 和 GhostDriver 1.0.4、JDK 1.7 和 Win 7 操作系统中运行基于 Java 的 Selenium 测试。

我也在使用 BrowserMob 代理,这样我就可以捕获网络流量来验证一些网络调用。下面给出的是我的代码的样子。

    server = new ProxyServer(44444);
    server.start();
    final Proxy proxy = server.seleniumProxy();
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, proxy);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--ignore-ssl-errors=yes" });
    capabilities.setCapability("browserType", "phantomjs");
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, System.getenv("PHANTOMJS_EXECUTABLE_PATH_PROPERTY"));
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY, System.getenv("GHOST_DRIVER_HOME") + "\\main.js");
    driver = new PhantomJSDriver(capabilities);

然后我执行我的测试。有时测试通过没有任何错误,有时我得到以下 2 个不同的错误。我不确定是什么原因造成的。

如果你能帮助我或者给我一个关于这里可能有什么问题的线索。如果需要,我可以提供更具体的信息。

[ERROR - 2013-07-30T14:05:46.693Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1375193146688
[ERROR - 2013-07-30T14:05:46.713Z] RouterReqHand - _handle - Thrown => {
  "message": "Error Message => 'Currently Window handle/name is invalid (closed?)'\n caused by Request => {\"headers\":{\"Accept\":\"application/json, image/png\",\"Connection\":\"Keep-Alive\",\"Host\":\"localhost:32417\"},\"httpVersion\":\"1.1\",\"method\":\"DELETE\",\"url\":\"/cookie\",\"urlParsed\":{\"anchor\":\"\",\"query\":\"\",\"file\":\"cookie\",\"directory\":\"/\",\"path\":\"/cookie\",\"relative\":\"/cookie\",\"port\":\"\",\"host\":\"\",\"password\":\"\",\"user\":\"\",\"userInfo\":\"\",\"authority\":\"\",\"protocol\":\"\",\"source\":\"/cookie\",\"queryKey\":{},\"chunks\":[\"cookie\"]},\"urlOriginal\":\"/session/f6843ca0-f91f-11e2-a28f-21e9e63595b3/cookie\"}",
  "name": "NoSuchWindow",
  "errorStatusCode": 23,
  "errorSessionId": "f6843ca0-f91f-11e2-a28f-21e9e63595b3",
  "errorClassName": "SessionReqHand",
  "errorScreenshot": "",
  "line": 193,
  "sourceId": 79329192,
  "sourceURL": "request_handlers/request_handler.js",
  "stack": "NoSuchWindow: Error Message => 'Currently Window handle/name is invalid (closed?)'\n caused by Request => {\"headers\":{\"Accept\":\"application/json, image/png\",\"Connection\":\"Keep-Alive\",\"Host\":\"localhost:32417\"},\"httpVersion\":\"1.1\",\"method\":\"DELETE\",\"url\":\"/cookie\",\"urlParsed\":{\"anchor\":\"\",\"query\":\"\",\"file\":\"cookie\",\"directory\":\"/\",\"path\":\"/cookie\",\"relative\":\"/cookie\",\"port\":\"\",\"host\":\"\",\"password\":\"\",\"user\":\"\",\"userInfo\":\"\",\"authority\":\"\",\"protocol\":\"\",\"source\":\"/cookie\",\"queryKey\":{},\"chunks\":[\"cookie\"]},\"urlOriginal\":\"/session/f6843ca0-f91f-11e2-a28f-21e9e63595b3/cookie\"}\n    at request_handlers/request_handler.js:193\n    at request_handlers/request_handler.js:168\n    at request_handlers/session_request_handler.js:785\n    at request_handlers/session_request_handler.js:178\n    at request_handlers/request_handler.js:61\n    at request_handlers/router_request_handler.js:78",
  "stackArray": [
    {
      "sourceURL": "request_handlers/request_handler.js",
      "line": 193
    },
    {
      "sourceURL": "request_handlers/request_handler.js",
      "line": 168
    },
    {
      "sourceURL": "request_handlers/session_request_handler.js",
      "line": 785
    },
    {
      "sourceURL": "request_handlers/session_request_handler.js",
      "line": 178
    },
    {
      "sourceURL": "request_handlers/request_handler.js",
      "line": 61
    },
    {
      "sourceURL": "request_handlers/router_request_handler.js",
      "line": 78
    }
  ]
}

这是我不时遇到的另一个例外。

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    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.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59)
    at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:34)
    at com.sun.proxy.$Proxy8.isEnabled(Unknown Source)
    at com.ihg.dec.apps.hi.test.selenium.homepage.HomePage.transitionToHotelSearchResultsPage(HomePage.java:402)
    at com.ihg.dec.apps.hi.test.selenium.homepage.HomePage.transitionToHotelSearchResultsPage(HomePage.java:381)
    at com.ihg.dec.apps.hi.test.selenium.homepage.HomePage.transitionToHotelSearchResultsPage(HomePage.java:377)
    at com.ihg.dec.apps.hi.test.selenium.pixel.BasePixelTest.gotoSearchResultPage(BasePixelTest.java:522)
    at com.ihg.dec.apps.hi.test.selenium.pixel.BasePixelTest.gotoRoomRatePage(BasePixelTest.java:501)
    at com.ihg.dec.apps.hi.test.selenium.pixel.BasePixelTest.gotoGuestInfoPage(BasePixelTest.java:397)
    at com.ihg.dec.apps.hi.test.selenium.pixel.PixelRegressionTest.testPixelOnGuestInfoPage(PixelRegressionTest.java:333)
    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:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.openqa.selenium.WebDriverException: java.net.SocketException: Software caused connection abort: recv failed
Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:75)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
    ... 39 more
Caused by: java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166)
    at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:281)
    at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
    at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
    at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
    at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:316)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:295)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:66)
    ... 40 more
4

0 回答 0