Unable to establish websocket connection
Asked Answered
F

10

37

I had coded automation testing in selenide but strange time comes up.

The browser window not able to establish websocket connection to http://localhost:2757/devtools/browser/uuid

> [ERROR] Tests run: 97, Failures: 1, Errors: 0, Skipped: 96, Time
> elapsed: 3.945 s <<< FAILURE! - in
> com.rev.testManager.GenericTestManager [ERROR]
> com.rev.testManager.GenericTestManager.openPage  Time elapsed: 3.727 s
> <<< FAILURE!
> org.openqa.selenium.remote.http.ConnectionFailedException: Unable to
> establish websocket connection to
> http://localhost:2757/devtools/browser/d5f72b05-f030-41ee-88b2-5823e7d0f35c
> Build info: version: '4.4.0', revision: 'e5c75ed026a' System info:
> host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch:
> 'amd64', os.version: '5.14.0-283.el9.x86_64', java.version: '18.0.2'
> Driver info: driver.version: SelenideDriver selenide.url:
> https://www.buletintv3.my/ selenide.baseUrl:
> https://www.buletintv3.my/    at
> org.openqa.selenium.remote.http.netty.NettyWebSocket.<init>(NettyWebSocket.java:102)
>   at
> org.openqa.selenium.remote.http.netty.NettyWebSocket.lambda$create$3(NettyWebSocket.java:128)
>   at
> org.openqa.selenium.remote.http.netty.NettyClient.openSocket(NettyClient.java:106)
>   at org.openqa.selenium.devtools.Connection.<init>(Connection.java:77)
>   at
> org.openqa.selenium.chromium.ChromiumDriver.lambda$new$2(ChromiumDriver.java:116)
>   at java.base/java.util.Optional.map(Optional.java:260)  at
> org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:114)
>   at
> org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:81)
>   at
> com.codeborne.selenide.webdriver.ChromeDriverFactory.create(ChromeDriverFactory.java:42)
>   at
> com.codeborne.selenide.webdriver.WebDriverFactory.createWebDriverInstance(WebDriverFactory.java:109)
>   at
> com.codeborne.selenide.webdriver.WebDriverFactory.createWebDriver(WebDriverFactory.java:69)
>   at
> com.codeborne.selenide.drivercommands.CreateDriverCommand.lambda$createDriver$0(CreateDriverCommand.java:76)
>   at
> com.codeborne.selenide.logevents.SelenideLogger.get(SelenideLogger.java:166)
>   at
> com.codeborne.selenide.drivercommands.CreateDriverCommand.createDriver(CreateDriverCommand.java:52)
>   at
> com.codeborne.selenide.impl.WebDriverThreadLocalContainer.createDriver(WebDriverThreadLocalContainer.java:180)
>   at
> com.codeborne.selenide.impl.WebDriverThreadLocalContainer.getAndCheckWebDriver(WebDriverThreadLocalContainer.java:149)
>   at
> com.codeborne.selenide.WebDriverRunner.getAndCheckWebDriver(WebDriverRunner.java:130)
>   at
> com.codeborne.selenide.impl.StaticDriver.getAndCheckWebDriver(StaticDriver.java:65)
>   at
> com.codeborne.selenide.SelenideDriver.getAndCheckWebDriver(SelenideDriver.java:220)
>   at
> com.codeborne.selenide.drivercommands.Navigator.lambda$navigateTo$0(Navigator.java:72)
>   at
> com.codeborne.selenide.logevents.SelenideLogger.run(SelenideLogger.java:153)
>   at
> com.codeborne.selenide.drivercommands.Navigator.navigateTo(Navigator.java:70)
>   at
> com.codeborne.selenide.drivercommands.Navigator.open(Navigator.java:32)
>   at
> com.codeborne.selenide.SelenideDriver.open(SelenideDriver.java:101)
>   at com.codeborne.selenide.Selenide.open(Selenide.java:52)   at
> com.rev.testManager.GenericTestManager.openPage(GenericTestManager.java:27)
>   at
> java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
>   at java.base/java.lang.reflect.Method.invoke(Method.java:577)   at
> org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
>   at
> org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
>   at
> org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:361)
>   at
> org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
>   at
> org.testng.internal.invokers.TestInvoker.runConfigMethods(TestInvoker.java:816)
>   at
> org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:590)
>   at
> org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
>   at
> org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
>   at
> org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:962)
>   at
> org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
>   at
> org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
>   at
> org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
>   at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)   at
> org.testng.TestRunner.privateRun(TestRunner.java:806)     at
> org.testng.TestRunner.run(TestRunner.java:601)    at
> org.testng.SuiteRunner.runTest(SuiteRunner.java:433)  at
> org.testng.SuiteRunner.runSequentially(SuiteRunner.java:427)  at
> org.testng.SuiteRunner.privateRun(SuiteRunner.java:387)   at
> org.testng.SuiteRunner.run(SuiteRunner.java:330)  at
> org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)  at
> org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)   at
> org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)     at
> org.testng.TestNG.runSuitesLocally(TestNG.java:1176)  at
> org.testng.TestNG.runSuites(TestNG.java:1099)     at
> org.testng.TestNG.run(TestNG.java:1067)   at
> org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:151)
>   at
> org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:111)
>   at
> org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:98)
>   at
> org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:155)
>   at
> org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:456)
>   at
> org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:169)
>   at
> org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:595)
>   at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:581)
Fascinator answered 9/3, 2023 at 3:18 Comment(3)
I had disable the firewall but still cannot. This happen after i invalidate the caches.Fascinator
Im using Centos 9 Stream OSFascinator
why arent you using ws?Pincers
O
66

I managed to solve it by adding an option:

options.addArguments("--remote-allow-origins=*");

There is a discussion about it in google group https://groups.google.com/g/chromedriver-users/c/xL5-13_qGaA

Oneirocritic answered 9/3, 2023 at 9:5 Comment(3)
How to do it in Selenide framework?Fascinator
It's already done in Selenide 6.12.2. You just need to upgrade, no need to add any options.Dippy
@Fascinator - For Selenide you can add this line before opening the browser - Configuration.browserCapabilities = new ChromeOptions().addArguments("--remote-allow-origins=*");Overpass
O
37

Create chrome option class object and pass into your ChromeDriver class like below:

ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
ChromeDriver driver = new ChromeDriver(options);

Now Selenium 4.8.2 version release and can resolve this issue by using this version without using above code

Overall answered 12/3, 2023 at 5:38 Comment(0)
K
10

This solution worked for me (I'm using Selenium WebDriver). I downloaded the newest chromedriver.exe with 111.0.5563.64 version. Then I added one more dependency:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-http-jdk-client</artifactId>
    <version>4.5.0</version>
</dependency>

and added this code line at the first line into @BeforeTest method:

System.setProperty("webdriver.http.factory", "jdk-http-client");

Hope this help! Thanks Phaneesh Kashyap!!! If this is not work for you. You can keep searching on this (https://groups.google.com/g/chromedriver-users/c/xL5-13_qGaA)

Kirtley answered 11/3, 2023 at 9:29 Comment(4)
Adding dependency worked for me. One additional property need to be added is: --remote-allow-origins=* No need to add property System.setProperty("webdriver.http.factory", "jdk-http-client");Fistulous
@KESHAVKUMAR If you add the dependency (which you should do if you can), you do not need to to add the Option for --remote-allow-origins.Auspicious
This is the best solution for Java 11+ users until we release a new version of Selenium. The old HTTP Client is not well maintained, and this new one will eventually be made the default.Auspicious
But this method requires Java 11+, for example Java 17.Filaria
F
3

Add --remote-allow-origins=* while initializing the driver instance.

 ChromeOptions chromeOptions = new ChromeOptions();
 chromeOptions.addArguments("--remote-allow-origins=*");
 ChromeDriver driver = new ChromeDriver(chromeOptions);

Also add below dependency or corresponding jar to project class path.

 <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-http-jdk-client</artifactId>
        <version>4.8.1</version>
 </dependency>
 
Fistulous answered 15/3, 2023 at 13:36 Comment(0)
C
1

Upgrading the Selenium lib worked for me (was on version 4.4.0):

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.9.0</version>
</dependency>

I suspect they now just add the --remote-allow-origins=* arg by default. 🙂

Contention answered 24/4, 2023 at 1:8 Comment(0)
M
1

Java 11 + selenium 4.8.2 and above is working without adding the chrome options. Selenium 4.8.2 + Java 8 is not and generate the websocket exception.

Marienbad answered 27/4, 2023 at 19:36 Comment(0)
I
0

For Edge Browser you can use below code it worked for me

EdgeOptions options = new EdgeOptions();
        options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
        options.addArguments("--remote-allow-origins=*");
        options.setCapability("ignore-certificate-errors", true);
         
WebDriverManager.edgedriver().avoidResolutionCache().proxy(PROXY).setup();
        driver.set(new EdgeDriver(options));
        driver.get().manage().window().maximize();
        driver.get().manage().deleteAllCookies();
Ite answered 3/5, 2023 at 6:45 Comment(1)
what is "PROXY" at line number 5 in the code example.Peonage
M
0

I had same problem, but in my case seems a problem just of Chrome/chromedriver! Using Windows 10, Java 8, Selenium 4.3.0, and Chrome 114 (last Chrome, May 2023) do not work! Changing Chrome, to old version Chrome 105 (and the according chromedriver), it works normally!

Madras answered 31/5, 2023 at 15:48 Comment(0)
S
0

Hi was upgrading Selenium from 3.141.59 to 4.5.0 by following https://www.selenium.dev/documentation/webdriver/troubleshooting/upgrade_to_selenium_4/. After upgrade I got this error. When I upgrade to 4.10.0 the error is resolved with out any change to the code.

Stanley answered 19/4 at 6:5 Comment(0)
W
-2

Change the selenium java version on the pom file. like

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
Worl answered 16/3, 2023 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.