java.io.IOException : Connection was aborted by the software in your host machine with Sendkey() in selenium java 异常

标签 java selenium selenium-webdriver webdriverwait executionexception

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

我正在完成我的作业,用 selenium 测试一个程序。 我正在使用教授提供的代码,它在我的 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.

最佳答案

这个错误信息...

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

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

根据讨论 ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine with GeckoDriver and Firefox当您尝试在 JavaScript 时调用 sendKeys() 时会出现此问题/jQuery仍然活跃。

解决方案

解决方案是为 JavaScript 引入 WebDriverWait/jQuery使用 ExpectedConditions 中的任何一个来完成:

关于java.io.IOException : Connection was aborted by the software in your host machine with Sendkey() in selenium java 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53562990/

相关文章:

java - 如何运行 java jar 文件并将输出存储在 shell 脚本变量中

selenium - 如何使用selenium webdriver处理ModalDialog?

python - 在 fedora 上安装 python selenium 绑定(bind)时出错

java - 如何使用 Java 处理 Selenium WebDriver 中的弹出窗口

java - 欧拉计划 #4 : Java

java - Android - 密码转换(将 * 转换为文本)

java - 如何使用appium在移动应用程序中实现卡支付自动化?

python - 在 for 循环中不匹配时退出 python 脚本

java - 实例化一个使用 protected 访问说明符继承的内部类

python - Selenium Webdriver (Python) - 单击 div 元素(复选框)