gpt4 book ai didi

java - TestNG - java.net.SocketException

转载 作者:行者123 更新时间:2023-12-01 06:11:11 24 4
gpt4 key购买 nike

我的设置: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();
}

}

测试正在运行,所以它不会干扰测试用例,但我真的很想理解并删除这个异常。

感谢您的任何想法。

最佳答案

我在想WebDriver中的某个地方使用了java.net。您的本地主机网络服务器正在关闭套接字或它已过早关闭。不要使用Before和After测试,而是尝试将其全部编写在一个测试方法中并进行调试。不幸的是,堆栈跟踪中没有提及您的类来查明哪个调用导致了问题。

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

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

关于java - TestNG - java.net.SocketException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34292067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com