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 access Chrome DevTools from WebDriverManager.chromedriver().browserInDocker() #947

Closed
seanyyyyyy opened this issue Nov 27, 2022 · 9 comments

Comments

@seanyyyyyy
Copy link

seanyyyyyy commented Nov 27, 2022

Description of the problem:
Running chrome browser in Docker and attempting to access ChromeDriver DevTools
However casting it to the created browser throws an error

Browser and version:
ChromeDriver 107.0.5304.62

Operating system:
Linux

WebDriverManager version:
5.3.1

WebDriverManager call:
WebDriverManager wdm = WebDriverManager.chromedriver().browserInDocker();
WebDriver driver = wdm.create();

DevTools chromeDevTools = ((ChromeDriver) driver).getDevTools();
chromeDevTools.createSession();

WebDriverManager traces:

Error log:
java.lang.ClassCastException at BetTests.java:33

@bonigarcia
Copy link
Owner

The method .browserInDocker() returns an instance of RemoteWebDriver, so that casting is not going to work. Instead, you should use the following:

WebDriver augmentedDriver = new Augmenter().augment(driver);
DevTools devTools = ((HasDevTools) augmentedDriver).getDevTools();

But even that it is not going to work, since internally WebDriverManager uses the Aerokube Docker images, and currently, the support for CDP is an open issue.

@batounen
Copy link

batounen commented Dec 3, 2022

Suddenly from yesterday ChromeDriver initialization is having issue.

Throwing:

  • org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
  • Caused by: org.openqa.selenium.WebDriverException: Driver server process died prematurely.

Any idea why? Firefox driver is working without any issue.

@yaggarwal
Copy link

@bonigarcia Is there any update on this? When can we expect for DevTools to work with Docker?

@bonigarcia
Copy link
Owner

I don't have any news about it, sorry. The support for CDP in Aerokube's images is still an open issue.

@yaggarwal
Copy link

@bonigarcia there is an update on that ticket today:
this was released in https://github.com/aerokube/selenoid/releases/tag/1.11.0
Can u check that if possible

@yaggarwal
Copy link

@bonigarcia any chance to take a look at this?

@bonigarcia
Copy link
Owner

I don't have the time to look into this, sorry. You can contribute to the project with a PR about it if you need it.

@bonigarcia
Copy link
Owner

bonigarcia commented Oct 27, 2023

I managed to implement a test using dockerized browsers through WebDriverManager and CDP:

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

This will require use the host network in Docker and WebDriverManager 5.6.0, just released.

Unfortunately, I managed to get this test working in local, but not in GitHub Actions. In GH Actions I get a "connection refused" when connecting to http://localhost:4444/ (see question).

@bonigarcia
Copy link
Owner

I confirmed this is also working in GH Actions. For example:

For executing in GH Actions, it is important not to run the test after Xvfb is started. For some reason, using Xvfb does not allow us to use port 4444 in the same session.

In summary, the support for CDP through dockerized browsers required the use of the host Docker network, use and WebDriver augmenters, and avoid Xvfb:

    WebDriver driver;
    DevTools devTools;
    WebDriverManager wdm = WebDriverManager.chromedriver().browserInDocker()
            .dockerNetworkHost();

    @BeforeEach
    void setupTest() throws Exception {
        assumeThat(isDockerAvailable()).isTrue();
        driver = new Augmenter().augment(wdm.create());
        devTools = ((HasDevTools) driver).getDevTools();
        devTools.createSession();
    }

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

No branches or pull requests

4 participants