33

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)
borchvm
  • 3,533
  • 16
  • 44
  • 45
nicholas
  • 2,581
  • 14
  • 66
  • 104

9 Answers9

57

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

Egor Stepanov
  • 745
  • 5
  • 7
31

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

Sadik Ali
  • 1,129
  • 10
  • 26
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)

PhuocThua
  • 101
  • 5
  • 1
    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"); – KESHAV KUMAR Mar 15 '23 at 13:28
  • 1
    @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`. – titusfortner Mar 15 '23 at 16:19
  • 1
    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. – titusfortner Mar 15 '23 at 16:20
  • But this method requires Java 11+, for example Java 17. – happy_marmoset Apr 11 '23 at 06:14
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>
 
KESHAV KUMAR
  • 140
  • 1
  • 7
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.

Craigo
  • 3,384
  • 30
  • 22
0

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.

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();
Saad
  • 26
  • 5
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!

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