TestNG - java.net.SocketException

时间:2015-12-15 14:42:51

标签: java testng testng-eclipse

我的设置: TestNG 6.9.10 - Java 1.8 - Eclipse Mars.1发行版(4.5.1) Windows 10

每次运行TestNG测试套件时都会出现此错误:

java.net.SocketException: Software caused connection abort: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(Unknown Source)
    at java.net.SocketOutputStream.write(Unknown Source)
    at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
    at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)
    at java.io.ObjectOutputStream.<init>(Unknown Source)
    at org.testng.remote.strprotocol.SerializedMessageSender.sendMessage(SerializedMessageSender.java:24)
    at org.testng.remote.strprotocol.MessageHub.sendMessage(MessageHub.java:43)
    at org.testng.remote.RemoteTestNG$RemoteSuiteListener.onStart(RemoteTestNG.java:257)
    at org.testng.SuiteRunner.invokeListeners(SuiteRunner.java:208)
    at org.testng.SuiteRunner.run(SuiteRunner.java:266)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)

即使我的测试类是空的:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class sample {

    public WebDriver driver;


    @Test
    public void f() {
    }

    @BeforeTest
    public void beforeTest() {
        driver = new FirefoxDriver();
        driver.get("http://localhost:8081/login.html?profile=desktop");
    }

    @AfterTest
    public void afterTest() {
        driver.close();
    }

}

测试正在运行,因此它不会干扰测试用例,但我真的想了解并删除此异常。

谢谢你的任何想法。

1 个答案:

答案 0 :(得分:-1)

我正在思考WebDriver中的某个地方,使用了java.net。您的localhost网络服务器正在关闭套接字或它过早关闭。而不是使用Before和After测试,尝试在一个Test方法和调试中编写它。不幸的是,在堆栈跟踪中没有提到您的类来确定哪个调用导致了问题。

逐步执行以下操作,查看抛出异常的位置。如果它在driver.get调用上,则您的http服务器可能拒绝连接。如果它在close()处抛出,则连接已被删除(可能被服务器拒绝)。

@Test
public void test() {
    driver = new FirefoxDriver();
    driver.get("http://localhost:8081/login.html?profile=desktop");
    driver.close();
}