JAVA + SpringBoot + Selenium Automation

wljmcqd8  于 2023-06-20  发布在  Java
关注(0)|答案(1)|浏览(117)

当我运行项目时,一切都很好,但是在测试的中间,浏览器关闭了自己,控制台抛出了下面的错误

2023-06-14T15:27:44.720-03:00  WARN 10544 --- [cHttpClient-1-4] o.a.netty.handler.WebSocketHandler       : onError

java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394) ~[na:na]
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426) ~[na:na]
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:256) ~[netty-buffer-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132) ~[netty-buffer-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
    at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

2023-06-14T15:27:44.736-03:00  WARN 10544 --- [cHttpClient-1-4] o.openqa.selenium.remote.http.WebSocket  : Connection reset

java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394) ~[na:na]
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426) ~[na:na]
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:256) ~[netty-buffer-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132) ~[netty-buffer-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
    at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

已尝试将网络适配器配置更改为Internet协议4并指定DNS首选地址。然后运行cmd并使用ipconfig /flushdns ipconfig /release ipconfig /renew netsh winsock reset
还是不行
JUnit告诉我发生错误的行在这个方法中

public void fillForm(String nombre, String email, String asunto, String mensaje) throws InterruptedException {
    WebElement nombreInput = driver.findElement(By.name("your-name"));  
    nombreInput.sendKeys(nombre);
    WebElement emailInput = driver.findElement(By.name("your-email"));
    emailInput.sendKeys(email);
    WebElement asuntoInput = driver.findElement(By.name("your-subject"));
    asuntoInput.sendKeys(asunto);
    WebElement mensajeInput = driver.findElement(By.name("your-message"));
    mensajeInput.sendKeys(mensaje);
syqv5f0l

syqv5f0l1#

此错误消息...

2023-06-14T15:27:44.720-03:00  WARN 10544 --- [cHttpClient-1-4] o.a.netty.handler.WebSocketHandler       : onError
java.net.SocketException: Connection reset

...表示在WebDriver初始化客户端时发生了SocketException

java.net.SocketException:连接重置

java.net.SocketException可能由于以下几种可能的原因而发生:

  • 当客户端在通过套接字返回响应之前关闭套接字连接时,可能会在服务器端发生这种情况。例如,在检索响应之前退出浏览器。
  • 它也可以通过写入另一端已经正常关闭的连接而发生,从而导致应用程序协议错误。

但在大多数使用Selenium的情况下,主要原因似乎是添加/使用了 * 不正确的库 *。

解决方案

要解决这个问题,请删除所有的jar/库,下载最新的稳定版selenium-server-4.10.0.jar,添加到您的项目中并执行测试。
样本代码:

package Day1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class genericTestFirefox {

    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.google.com/");
    }
}

控制台输出:

Jun 15, 2023 1:44:30 AM org.openqa.selenium.remote.service.DriverService$Builder getLogOutput
INFO: Driver logs no longer sent to console by default; https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output

相关问题