SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.49k stars 8.15k forks source link

[🐛 Bug]: Can run my tests in recapitated mode but not in headless #12229

Closed ezrac0des closed 1 year ago

ezrac0des commented 1 year ago

What happened?

I can run any of my tests in Chrome recapitated (headfull) mode but when I try to run them in headless mode, I get the following output.

I have tried different permutations of the chrome options but the result didn't change.

At initial, I thought the problem was due to chromedriver but I got the same error with Firefox headless as well.

My webdrivermanager version is 5.3.2.

How can we reproduce the issue?

When I run this simple test with the given versions
`
    @Test
    public void test() {
        Driver.getDriver().get("https://www.google.ca/");
    }
`

My code in Driver:
`
        static ThreadLocal<WebDriver> driverPool = new ThreadLocal<>();
        HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
        chromePrefs.put("download.default_directory", System.getProperty("user.dir") + "\\target");

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setExperimentalOption("prefs", chromePrefs);
        chromeOptions.addArguments("use-fake-ui-for-media-stream");
        chromeOptions.addArguments("--window-size=1920,1080");
        chromeOptions.addArguments("--disable-gpu");
        chromeOptions.addArguments("--remote-allow-origins=*");
        chromeOptions.addArguments("lang=en-GB");
        chromeOptions.addArguments("--headless");
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--disable-dev-shm-usage");
        chromeOptions.setHeadless(true);
        WebDriverManager.chromedriver().setup();
        driverPool.set(new ChromeDriver(chromeOptions));
`

Relevant log output

[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Using chromedriver 114.0.5735.90 (resolved driver for Chrome 114)
[main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\user\.cache\selenium\chromedriver\win32\114.0.5735.90\chromedriver.exe
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 49153
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1687204620.180][WARNING]: Browser-wide DevTools client failed to connect: disconnected: unable to connect to renderer

Step failed
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: disconnected: not connected to DevTools
  (failed to check if window was closed: disconnected: not connected to DevTools)
  (Session info: headless chrome=114.0.5735.134)
Build info: version: '4.4.0', revision: 'e5c75ed026a'
System info: host: , ip: , os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '19.0.1'

Operating System

Windows 11

Selenium version

Java 4.10.0

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

Chrome 114.0.5735.90

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

ChromeDriver 114.0.5735.134

Are you using Selenium Grid?

No

github-actions[bot] commented 1 year ago

@ezrac0des, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 1 year ago

Seems you are using Build info: version: '4.4.0', revision: 'e5c75ed026a', please upgrade and report back.

titusfortner commented 1 year ago

Also, you should use --headless=new

github-actions[bot] commented 10 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.