selenium: [πŸ› Bug]: Unable to establish websocket connection to http://x.x.x.x:4444/session/${session}/se/cdp

What happened?

My objective is: to retrieve information in a xhr response body, sent by a submitted filled in form

My approach is: to use DevTools.

  1. locally, my approach is working
  2. remotely, my approach isn’t working indeed i have this exception 14:29:12 org.openqa.selenium.remote.http.ConnectionFailedException: 14:29:12 Unable to establish websocket connection to http://x.x.x.x:4444/session/${session}/se/cdp 14:29:12 Build info: version: β€˜4.0.0’, revision: β€˜3a21814679’ 14:29:12 System info: host: β€˜c54d6a2a855f’, ip: β€˜10.0.5.6’, os.name: β€˜Linux’, os.arch: β€˜amd64’, os.version: β€˜3.10.0-1160.45.1.el7.x86_64’, java.version: β€˜11.0.12’ 14:29:12 Driver info: driver.version: unknown

How can we reproduce the issue?

**DevTools**
Code to use DevTools
-----------------------
        WebDriver augmentedDriver= new Augmenter().augment(WebDriverRunner.getWebDriver());
        DevTools devTools = ((ChromeDriver) augmentedDriver).getDevTools();
        devTools.createSession();
        devTools.send(Network.enable(Optional.of(100000000), Optional.empty(), Optional.empty()));
        final String[] textFromResponseBody= new String[1];
        devTools.addListener(Network.responseReceived(), responseReceived -> {
            if (responseReceived.getResponse()
                                .getUrl()
                                .contains(PATH_CONTEXT)) {
                textFromResponseBody[0] = devTools.send(Network.getResponseBody(responseReceived.getRequestId()))
                                                           .getBody();
            }
        });

after the filling in the form
-----------------------------
        log.info("clickOnSubmit " + SUBMIT_BUTTON);
        SUBMIT_BUTTON.should(enabled, visible)
                     .click();

confirmation of extracting the responseBody
-------------------------------------------
         log.info("Work request ID : {}", textFromResponseBody[0]);

**NetworkInterceptor**
        final String[] textFromResponseBody= new String[1];
        NetworkInterceptor interceptor = new NetworkInterceptor(
                (((ChromeDriver)new Augmenter().augment(WebDriverRunner.getWebDriver()))),
                (Filter) next -> req -> {
                    HttpResponse res = next.execute(req);
                    if ( req.getUri().contains(PATH_CONTEXT)) {
                        log.info(res.getContentString());
                        textFromResponseBody[0] = res.getContentString();
                    }
                    return res;
                }
        );

Relevant log output

14:29:11  Dec 07, 2021 1:28:54 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
14:29:11  INFO: Found exact CDP implementation for version 95
14:29:11  Dec 07, 2021 1:29:04 PM org.openqa.selenium.remote.http.netty.NettyWebSocket lambda$new$0
14:29:11  WARNING: connection timed out: /x.x.x.x:4444
14:29:11  java.net.ConnectException: connection timed out: /x.x.x.x:4444
14:29:11  	at org.asynchttpclient.netty.channel.NettyConnectListener.onFailure(NettyConnectListener.java:179)
14:29:11  	at org.asynchttpclient.netty.channel.NettyChannelConnector$1.onFailure(NettyChannelConnector.java:108)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:28)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:20)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117)
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:262)
14:29:11  	at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)
14:29:11  	at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170)
14:29:11  	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
14:29:11  	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
14:29:11  	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
14:29:11  	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
14:29:11  	at java.base/java.lang.Thread.run(Thread.java:866)
14:29:11  Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /10.42.2.196:4444
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261)
14:29:11  	... 9 more
14:29:11  
14:29:11  Dec 07, 2021 1:29:04 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
14:29:11  WARNING: connection timed out: /x.x.x.x:4444
14:29:11  java.net.ConnectException: connection timed out: /x.x.x.x:4444
14:29:11  	at org.asynchttpclient.netty.channel.NettyConnectListener.onFailure(NettyConnectListener.java:179)
14:29:11  	at org.asynchttpclient.netty.channel.NettyChannelConnector$1.onFailure(NettyChannelConnector.java:108)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:28)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:20)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117)
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:262)
14:29:11  	at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)
14:29:11  	at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170)
14:29:11  	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
14:29:11  	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
14:29:11  	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
14:29:11  	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
14:29:11  	at java.base/java.lang.Thread.run(Thread.java:866)
14:29:11  Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /10.42.2.196:4444
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261)
14:29:11  	... 9 more
14:29:11  
...
...
14:29:12  [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 51.575 s <<< FAILURE! - in TestSuite
14:29:12  [ERROR] ...  Time elapsed: 46.934 s  <<< FAILURE!
14:29:12  org.openqa.selenium.remote.http.ConnectionFailedException: 
14:29:12  Unable to establish websocket connection to http://x.x.x.x:4444/session/${session}/se/cdp
14:29:12  Build info: version: '4.0.0', revision: '3a21814679'
14:29:12  System info: host: 'c54d6a2a855f', ip: '10.0.5.6', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.45.1.el7.x86_64', java.version: '11.0.12'
14:29:12  Driver info: driver.version: unknown
14:29:12  	at ...
14:29:12  
14:29:12  [INFO]

Operating System

Docker Debian GNU/Linux 11 (bullseye)

Selenium version

openjdk 11.0.13 2021-10-19

What are the browser(s) and version(s) where you see this issue?

Chrome 95

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 95 via Selenide / WebDriverManager

Are you using Selenium Grid?

Selenium Grid 4.1.0 (revision aea69daa1c)

my comments

i see we want to connect to a websocket but the protocol is http …

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (8 by maintainers)

Most upvoted comments

Well, a Grid should not be exposed to the internet… There is a way to set a user and a password https://www.selenium.dev/documentation/grid/configuration/cli_options/#router

After reading again, the issue is that the connection to the websocket cannot be done because it is attempted with the internal docker container IP. To avoid that, please check how to set the Grid url in docker-selenium.

I have not looked yet, I try to not work during the weekends.