SeleniumHQ / selenium

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

[🐛 Bug]: SessionNotCreatedException with Chromium/Windows after upgrading from 4.8.3 to 4.9.0 #11946

Closed MohabMohie closed 1 year ago

MohabMohie commented 1 year ago

What happened?

If I set the platFormName option

chOptions = new ChromeOptions();
chOptions.setCapability(CapabilityType.PLATFORM_NAME, Platform.WINDOWS);
driver.set(new ChromeDriver(chOptions));

It fails for local execution on Chromium based browsers (Chrome/Edge) only on WINDOWS. The same works fine for Linux and MacOS, and the same code works fine on 4.8.3

This is the exception stacktrace

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: No matching capabilities found 
Host info: host: 'MOHAB-MOHIE', ip: '192.168.1.25'
Build info: version: '4.9.0', revision: 'd7057100a6'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '20.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*], extensions: []}, platformName: WINDOWS}]}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:136)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:94)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:68)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:165)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:183)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:84)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:73)

How can we reproduce the issue?

chOptions = new ChromeOptions();
chOptions.setCapability(CapabilityType.PLATFORM_NAME, Platform.WINDOWS);
driver.set(new ChromeDriver(chOptions));

Relevant log output

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: No matching capabilities found 
Host info: host: 'MOHAB-MOHIE', ip: '192.168.1.25'
Build info: version: '4.9.0', revision: 'd7057100a6'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '20.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*], extensions: []}, platformName: WINDOWS}]}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:136)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:94)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:68)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:165)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:183)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:84)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:73)

Operating System

Windows 11

Selenium version

Java 4.9.0

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

Chrome & Edge (Latest)

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

Using SeleniumManager to get the ChromeDriver

Are you using Selenium Grid?

No

github-actions[bot] commented 1 year ago

@MohabMohie, 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!

MohabMohie commented 1 year ago

@diemol created as per this slack thread: https://seleniumhq.slack.com/archives/C0ABCS03F/p1682411343366769

MohabMohie commented 1 year ago

I'll keep add more comments as I find more information that may be helpful to resolve the bug image

vicozohili commented 1 year ago

I am getting the same issue after upgrading from 4.8.3 to 4.9.0.

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Host info: host: '', ip: '' Build info: version: '4.9.0', revision: 'd7057100a6' System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.6' Driver info: org.openqa.selenium.chrome.ChromeDriver Command: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: true, browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --start-maximized, --enable-automation, --disable-infobars, --disable-extensions, --disable-gpu, --disable-dev-shm-usage, --no-sandbox, --disable-browser-side-navi..., --whitelisted-ips], excludeSwitches: [disable-popup-blocking], extensions: [], prefs: {download.default_directory: C:\Users\\git\cucumber-...}}, goog:loggingPrefs: org.openqa.selenium.logging..., pageLoadStrategy: normal, platformName: ANY}]}] at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:561) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:157) at org.openqa.selenium.chromium.ChromiumDriver.(ChromiumDriver.java:101) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:84)

Chrome is started using the following:

ChromeOptions options = new ChromeOptions(); options.setCapability(ChromeOptions.CAPABILITY, getCapabilities()); options.setPlatformName(Platform.ANY.name()); options.setPageLoadStrategy(PageLoadStrategy.NORMAL); if(getIsHeadlessLocalBrowser()) { options.addArguments("--headless=new"); // open headless browser } if(getMaximzeBrowserWindow()) { options.addArguments("--start-maximized"); // open browser in maximized mode } options.addArguments("--enable-automation"); options.addArguments("--disable-infobars"); // disabling infobars options.addArguments("--disable-extensions"); // disabling extensions options.addArguments("--disable-gpu"); // applicable to windows os only options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems options.addArguments("--no-sandbox"); // bypass OS security model options.addArguments("--disable-browser-side-navigation"); options.addArguments("--whitelisted-ips"); // bypass whitelisted ips options.setExperimentalOption("excludeSwitches", new ArrayList(Arrays.asList("disable-popup-blocking"))); // disable Pop-ups options.setExperimentalOption("prefs", browserPrefs); // browser preferences options.setAcceptInsecureCerts(true); // bypass SSL certs driver = new ChromeDriver(new ChromeDriverService.Builder().usingAnyFreePort().build(), options);

Two items to note:

  1. When the above is executed with 4.8.3 in windows, it fails using --headless=new, but works using --headless. In linux, similarly --headless=new works with 4.8.1 with browser downloads but fails with --headless for browser downloads.

  2. When executed with 4.9.0, in windows I get "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure." In linux, session starts but we face the browser downloads issue with --headless in linux and fails to start with --headless=new.

diemol commented 1 year ago

@vicozohili is this the same issue? Are you getting a failure when you specify platformName: WINDOWS?

MohabMohie commented 1 year ago

@diemol in my case it's clear that it's working with the same configuration before the upgrade, but failing "only when I specify the platformName" after the upgrade. I implemented a workaround in my test engine to check if the execution address is local to not set the platformName at all and it's working consistently across all operating systems.

vicozohili commented 1 year ago

@diemol @MohabMohie , great. By not specifying platformName at all with Selenium 4.9.0, running fine with --headless mode both standalone and using selenium grid on windows and linux.

However, when I specify the new --headless=new, browser is launched in windows via grid but not in linux using selenium grid. Grid is started with below commands:

--start hub java -Dwebdriver.http.factory=jdk-http-client -jar selenium-server-4.9.0.jar --ext selenium-http-jdk-client-4.9.0.jar hub

--start nodes java -Dwebdriver.http.factory=jdk-http-client -Dwebdriver.chrome.driver=chromedriver -Dwebdriver.chrome.whitelistedIps= -jar selenium-server-4.9.0.jar --ext selenium-http-jdk-client-4.9.0.jar node --override-max-sessions true --max-sessions 20 --session-timeout 72000

When browser is launched in linux with --headless=new, I get

15:29:11.851 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "fde6cf6a55101cdddf564fc423dbbea4","eventTime": 1682519351629655785,"eventName": "Session request received by the Distributor","attributes": {"logger": "org.openqa.selenium.grid.distributor.local.LocalDistributor","request.payload": "[Capabilities {acceptInsecureCerts: true, browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --headless=new, --start-maximized, --window-size=1920,1080, --enable-automation, --disable-infobars, --disable-extensions, --disable-gpu, --disable-dev-shm-usage, --no-sandbox, --disable-browser-side-navi..., --whitelisted-ips], excludeSwitches: [disable-popup-blocking], extensions: [], prefs: {download.default_directory: \u002fopt\u002finternal\u002fma\u002fjenkins\u002fwo...}}, goog:loggingPrefs: {browser: ALL, client: ALL, driver: ALL, performance: ALL, profiler: ALL, server: ALL}, pageLoadStrategy: normal}]"}}

15:29:11.851 WARN [SeleniumSpanExporter$1.lambda$export$1] - org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Host info: host: '', ip: '' Build info: version: '4.9.0', revision: 'd7057100a6' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.6.1.el7.x86_64', java.version: '17.0.5' Driver info: driver.version: unknown Build info: version: '4.9.0', revision: 'd7057100a6' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.6.1.el7.x86_64', java.version: '17.0.5' Driver info: driver.version: unknown Build info: version: '4.9.0', revision: 'd7057100a6' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.6.1.el7.x86_64', java.version: '17.0.5' Driver info: driver.version: unknown at org.openqa.selenium.grid.node.remote.RemoteNode.newSession(RemoteNode.java:150) at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:645) at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:564) at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:818) at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:779) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833)

But if I set --headless only, browser launches in linux. I believe --headless=new was introduced around selenium 4.8.1 where it worked.

diemol commented 1 year ago

@vicozohili can you please create a separate issue for the headless topic? This will help us to triage things properly.

MohabMohie commented 1 year ago

please note that the same issue was reproduced for Firefox locally. also working after removing the same capability.

diemol commented 1 year ago

I spent a while trying to reproduce this and it seems it is Java only. Since we removed completely JWP support, the payload we are sending to the driver is W3C WebDriver only. In Java, the platformName is sent upper case and looks like the driver does not like that. So Platform.WINDOWS ends up as the string WINDOWS, but if we send windows (lowercase), the driver is happy with it.

I will create an issue on ChromeDriver and GeckoDriver for this, but also do something in Selenium Java for it so we do not wait until the driver(s) fix it.

diemol commented 1 year ago

The workaround until this is fixed, is to send the platformName lowercase.

diemol commented 1 year ago

ChromeDriver issue: https://bugs.chromium.org/p/chromedriver/issues/detail?id=4441 GeckoDriver issue: https://github.com/mozilla/geckodriver/issues/2110

diemol commented 1 year ago

Closed via 000cb086e988c4682fcaae2cea65dbba0e62b927 This will be part of 4.9.1

diemol commented 1 year ago

If you want to try this before the official release of 4.9.1, add this repository to your pom.xml, and use version 4.9.1-SNAPSHOT.

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.