3

操作系统:Win7 64位浏览器:Chrome

我正在完成我的任务,用硒测试一个程序。我正在使用教授提供的代码,它在我的 localhost:8080 上创建了一个网络应用程序(所以应该没有任何连接问题)

public void canConenctTwoPlayers() {
    // connect
    //2: missing code
    this.indexPage.connect.click();
    assertThat(this.indexPage.hasText("Successfully connected to the game with unique "), is(true));
    this.indexPage.numberPlayers.click();
    this.indexPage.numberPlayers.sendKeys("2");
    this.indexPage.open.click();
    //second connect
    ChromeDriver second_player = quickConnectAnotherUser();
    //3: missing code
    assertThat(this.indexPage.hasText("The game is now ready to begin"), is(true));
    // quit
    //4: missing code
    disconnectSecondUser(second_player);
    this.indexPage.disconnect.click();      
}

这里的 numberPlayers 是窗口中的元素,正如它的名字所说,输入玩家的数量。但是当我使用 sendKeys 时,它给了我这个异常

java.io.IOException: java.util.concurrent.ExecutionException: 
java.io.IOException: Connection was aborted by the software in your host machine

当我注释掉发送键时,代码运行良好。

2018-11-30 13:24:52.749  INFO 18632 --- [nio-8080-exec-1] c.c.poker.game.PokerSocketHandler        : Opened new session for _fc6yznc.
2018-11-30 13:24:52.749  INFO 18632 --- [nio-8080-exec-1] ca.carleton.poker.game.PokerGame         : Player is trying to connect _fc6yznc, WebSocketServerSockJsSession[id=_fc6yznc]
2018-11-30 13:24:52.749  INFO 18632 --- [nio-8080-exec-1] ca.carleton.poker.game.PokerGame         : Setting first player as admin:_fc6yznc.
2018-11-30 13:24:52.749  INFO 18632 --- [nio-8080-exec-1] ca.carleton.poker.game.PokerGame         : Player is being added _fc6yznc, WebSocketServerSockJsSession[id=_fc6yznc]
2018-11-30 13:24:52.750  INFO 18632 --- [nio-8080-exec-1] ca.carleton.poker.game.PokerGame         : Sessions WebSocketServerSockJsSession[id=_fc6yznc]
2018-11-30 13:24:52.750  INFO 18632 --- [nio-8080-exec-1] c.c.poker.game.PokerSocketHandler        : Sending admin message to player.
2018-11-30 13:24:52.750  INFO 18632 --- [nio-8080-exec-1] ca.carleton.poker.game.PokerGame         : Current number of players is 1. Required number is 4.
2018-11-30 13:24:52.872 ERROR 18632 --- [nio-8080-exec-2] c.c.poker.game.PokerSocketHandler        : TRANSPORT ERROR - Error with the network.

java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: Connection was aborted by the software in your host machine
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:282)
at org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:570)
at org.apache.tomcat.websocket.WsSession.onClose(WsSession.java:510)
at org.apache.tomcat.websocket.WsFrameBase.processDataControl(WsFrameBase.java:342)
at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:284)
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:130)
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:60)
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:203)
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)
at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:663)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.util.concurrent.ExecutionException: java.io.IOException: Connection was aborted by the software in your host machine
at org.apache.tomcat.websocket.FutureToSendHandler.get(FutureToSendHandler.java:102)
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:275)
... 16 common frames omitted
Caused by: java.io.IOException: Connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(Unknown Source)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.write(Unknown Source)
at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:127)
at org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool.java:184)
at org.apache.coyote.http11.upgrade.NioServletOutputStream.doWriteInternal(NioServletOutputStream.java:94)
at org.apache.coyote.http11.upgrade.NioServletOutputStream.doWrite(NioServletOutputStream.java:61)
at org.apache.coyote.http11.upgrade.AbstractServletOutputStream.writeInternal(AbstractServletOutputStream.java:165)
at org.apache.coyote.http11.upgrade.AbstractServletOutputStream.write(AbstractServletOutputStream.java:132)
at org.apache.tomcat.websocket.server.WsRemoteEndpointImplServer.onWritePossible(WsRemoteEndpointImplServer.java:98)
at org.apache.tomcat.websocket.server.WsRemoteEndpointImplServer.doWrite(WsRemoteEndpointImplServer.java:80)
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:450)
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessage(WsRemoteEndpointImplBase.java:338)
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:270)
... 16 common frames omitted

2018-11-30 13:24:52.872  INFO 18632 --- [nio-8080-exec-2] c.c.poker.game.PokerSocketHandler        : Closing session for _fc6yznc with status CloseStatus[code=1000, reason=null].
2018-11-30 13:24:52.872  INFO 18632 --- [nio-8080-exec-2] c.c.poker.game.PokerSocketHandler        : Disabling all accounts because the admin left.
2018-11-30 13:24:52.873  INFO 18632 --- [nio-8080-exec-2] ca.carleton.poker.game.PokerGame         : Sessions WebSocketServerSockJsSession[id=_fc6yznc]
2018-11-30 13:24:52.873  INFO 18632 --- [nio-8080-exec-2] c.carleton.poker.session.SessionHandler  : Registered _fc6yznc for disconnect.
4

1 回答 1

3

此错误消息...

java.io.IOException: java.util.concurrent.ExecutionException: 
java.io.IOException: Connection was aborted by the software in your host machine

...暗示异常是由于并发执行而引发的。

根据讨论ConnectionAbortedError: [WinError 10053] 已建立的连接被您的主机中的软件与 GeckoDriver 和 Firefox 中止,当您在JavaScript / jQuery仍处于活动状态时尝试调用sendKeys()时会观察到此问题。

解决方案

解决方案是使用任何一个ExpectedConditions来诱导 WebDriverWait 让JavaScript / jQuery完成:

于 2018-11-30T21:29:22.027 回答