Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create devtools session in selenoid using selenium 4 #1175

Closed
hellfish46 opened this issue Feb 8, 2022 · 18 comments
Closed

Cannot create devtools session in selenoid using selenium 4 #1175

hellfish46 opened this issue Feb 8, 2022 · 18 comments

Comments

@hellfish46
Copy link

hellfish46 commented Feb 8, 2022

Hello. Tried to create devtools session with remote web driver but got error

java.lang.ClassCastException: class org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$oDUeXh8L cannot be cast to class org.openqa.selenium.devtools.HasDevTools (org.openqa.selenium.remote.RemoteWebDriver$ByteBuddy$oDUeXh8L is in unnamed module of loader net.bytebuddy.dynamic.loading.ByteArrayClassLoader @bf59c9c; org.openqa.selenium.devtools.HasDevTools is in unnamed module of loader 'app')

Used this way to get devtools:

WebDriver driver = new Augmenter().augment(new RemoteWebDriver(new URL(SELENOID_URL_HUB), getChromeOptions()));
        DevTools devTools = ((HasDevTools) driver).getDevTools();
        devTools.createSession();

Also I use bytebuddy for Augmenter:

<dependency>
    <groupId>net.bytebuddy</groupId>
    <artifactId>byte-buddy</artifactId>
    <version>1.12.4</version>
</dependency>

Created repository with simple project to demonstrate this:
https://github.com/hellfish46/SeleniumIssue

This way to creation of devtools session works locally. When I used selenium grid standalone I didn't get this error, but got another error with socket connection (doesn't matter=) )

Maybe I do something wrong.

@vania-pooh
Copy link
Member

@hellfish46 see #1146

@hellfish46
Copy link
Author

hellfish46 commented Feb 9, 2022

@vania-pooh Thank you for quick answer) sorry, didn't understand the solution what you come up with in #1146

Is it still in progress ?

@vania-pooh
Copy link
Member

vania-pooh commented Feb 9, 2022

@hellfish46 this will not be implemented because this is custom capability not present in W3C spec.

@hellfish46
Copy link
Author

@vania-pooh Ok, thanks for answer. Is there another way to use devtools on selenoid ?

@vania-pooh
Copy link
Member

@hellfish46 you can connect directly to devtools websocket. E.g. https://github.com/aerokube/chrome-developer-tools-protocol-java-example

@hellfish46
Copy link
Author

@vania-pooh Thanks a lot )

@jhainzlschmid
Copy link

I am not using selenoid, but regular Selenium, and got the same error when executing the packaged jar file. I will leave this here for anyone having a similar issue:
When creating a executable jar file you need to use the maven shade plugin. The maven assembly plugin did not work for me. In the shade configuration you have to add a ServiceResourceTransformer. My maven shade plugin configuration looks like this:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>YourMainClass</mainClass>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

@vania-pooh
Copy link
Member

@jhainzlschmid what you are showing does not seems to be related to this issue.

@sharutkarsh
Copy link

Do we have an update on this yet?

@vania-pooh
Copy link
Member

@sharutkarsh not yet.

@msoren1234
Copy link

@vania-pooh Do we have an update on this issue?

@msoren1234
Copy link

@hellfish46 Did you manage to fix your issue with Devtools session on Selenoid

@vania-pooh
Copy link
Member

@msoren1234 no updates for the moment.

@hellfish46
Copy link
Author

hellfish46 commented Feb 9, 2023

@hellfish46 Did you manage to fix your issue with Devtools session on Selenoid

Hello) I didn't manage to use devtools of Selenium 4 but I use dependency for this and it is working good:

com.github.kklisura.cdt
cdt-java-client
4.0.0

@yaggarwal
Copy link

Hello, Is there any update on this?

@vania-pooh
Copy link
Member

@bonigarcia
Copy link

WebDriverManager uses the Aerokube Docker images to provide browsers in Docker containers. I'm figuring out what is required to support CDP in these containers from WebDriverManager. For that, I created the following test example:

https://github.com/bonigarcia/webdrivermanager/blob/master/src/test/java/io/github/bonigarcia/wdm/test/docker/DockerChromeCdpTest.java

Internally, when wdm.create() is invoked, WebDriverManager pulls and starts a Docker container based on (at this moment) selenoid/vnc:chrome_117.0 image as follows:

2023-10-20 15:07:25 [main] DEBUG i.g.b.wdm.webdriver.WebDriverCreator.createRemoteWebDriver(81) -- Creating WebDriver object for chrome at http://localhost:32779/ with Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --disable-gpu], extensions: []}}

But then, the CDP endpoint connection is refused:

Oct 20, 2023 3:07:27 PM org.openqa.selenium.devtools.CdpEndpointFinder getCdpEndPoint
WARNING: Unable to connect to determine websocket url: java.net.ConnectException: Connection refused: localhost/127.0.0.1:38783

I tried to set the capability se:cdp with the Selenoid URL (http://localhost:32779/ in this example), but no luck.

@vania-pooh Do you know what I am missing here? Thanks.

@vania-pooh
Copy link
Member

@bonigarcia se:cdp and se:version capabilities required by Selenium client to establish a CDP connection are never returned by web driver binaries. So trying to execute this code against browser image directly will never work. Selenium and Selenoid are adding these capabilities manually to new session response once it's created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants