0

When I run the project everything goes just fine, but in the middle of the test the browser closes itself and console throws me the following error

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]

Tried changing the network adapter config goint to Internet Protocol 4 and specifying a DNS preferred adress. Then running cmd and using ipconfig /flushdns ipconfig /release ipconfig /renew netsh winsock reset

Still does not work

JUnit tells me that the line where the error happens is in this method

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);

1 Answers1

0

This error message...

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

...implies that SocketException occured while WebDriver was initializing the client.


java.net.SocketException: Connection reset

java.net.SocketException may occur due to several possible reasons as follows:

  • It can occur on the server-side when the client closed the socket connection before the response could be returned over the socket. For example, by quitting the browser before the response was retrieved.
  • It can also occur by writing to a connection that the other end has already closed normally resulting in an application protocol error.

But in majority of the cases using Selenium the main reason seems to incorrect libraries being added/used.


Solution

To get rid of this issue remove all the jars/libraries and download latest stable selenium-server-4.10.0.jar, add to your project and execute your test.

Sample Code:

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/");
    }
}

Console Output:

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    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352