SeleniumHQ / selenium

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

[🐛 Bug]: Unable run scripts using remote webdriver on remote machines #14197

Closed nairdinesh04 closed 5 days ago

nairdinesh04 commented 6 days ago

What happened?

Hi There,

I have a selenium grid hub and two nodes registered to the same. I can see the node sessions on selenium grid UI.

But I get error saying when executing my scripts and browsers are not getting launched: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

Selenium Version :

org.seleniumhq.selenium selenium-java 4.20.0

Browser - Chrome

How can we reproduce the issue?

My code to launch the browser using Remote Webdriver is : 

        if(Browser.contains("Chrome")) {        

            options = new ChromeOptions();
            if(Browser.contains("headless")) {
                ((ChromiumOptions<ChromeOptions>) options).addArguments("headless");
            }
            ((ChromiumOptions<ChromeOptions>) options).setExperimentalOption("excludeSwitches",Arrays.asList( "enable-automation"));
            //driver = new ChromeDriver(co);  //Driver - Without Grid

        }
        else if(Browser.equalsIgnoreCase("Firefox")){       
            FirefoxOptions options = new FirefoxOptions();
            //driver = new FirefoxDriver();
        }
//      else if(Browser.equalsIgnoreCase("IE")) {           
//          driver = new InternetExplorerDriver();
//          
//      }
        else if(Browser.equalsIgnoreCase("Edge")) {
            options = new EdgeOptions();
            ((ChromiumOptions<EdgeOptions>) options).setExperimentalOption("excludeSwitches",Arrays.asList( "enable-automation"));
            //driver = new EdgeDriver(co);
        }

        driver.set(new RemoteWebDriver(new URI("hub<ip>:<port>").toURL(), options));

### Relevant log output

```shell
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: 'xxxxxxxxx', ip: 'xxxxxxx'
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:536)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:232)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:161)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
    at com.crm.qa.base.TestBase.initializeTest(TestBase.java:89)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
    at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
    at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
    at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:700)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at org.testng.TestRunner.privateRun(TestRunner.java:794)
    at org.testng.TestRunner.run(TestRunner.java:596)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
    at org.testng.SuiteRunner.access$000(SuiteRunner.java:28)
    at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:418)
    at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:64)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: org.openqa.selenium.TimeoutException: java.net.http.HttpConnectTimeoutException: HTTP connect timed out
Build info: version: '4.20.0', revision: '866c76ca80'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '21.0.1'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute0(JdkHttpClient.java:386)
    at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
    at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:55)
    at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute(JdkHttpClient.java:352)
    at org.openqa.selenium.remote.tracing.TracedHttpClient.execute(TracedHttpClient.java:54)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:89)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:61)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:162)
    at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
    ... 29 more
Caused by: java.net.http.HttpConnectTimeoutException: HTTP connect timed out
    at java.net.http/jdk.internal.net.http.MultiExchange.toTimeoutException(MultiExchange.java:585)
    at java.net.http/jdk.internal.net.http.MultiExchange.getExceptionalCF(MultiExchange.java:532)
    at java.net.http/jdk.internal.net.http.MultiExchange.lambda$responseAsyncImpl$7(MultiExchange.java:452)
    at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:934)
    at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:911)
    at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
    at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2194)
    at java.net.http/jdk.internal.net.http.Http1Exchange.lambda$cancelImpl$9(Http1Exchange.java:592)
    ... 3 more
Caused by: java.net.ConnectException: HTTP connect timed out
    at java.net.http/jdk.internal.net.http.MultiExchange.toTimeoutException(MultiExchange.java:586)
    ... 10 more

Operating System

Windows 10

Selenium version

Java 4.20.0

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

Chrome - 126.0.6478.127

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

NA

Are you using Selenium Grid?

4.21.0

github-actions[bot] commented 6 days ago

@nairdinesh04, 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 6 days ago

Can you share the complete Grid logs? Hub and Node.

nairdinesh04 commented 6 days ago

Can you share the complete Grid logs? Hub and Node.

I dont see any logs on grid command prompt. The only logs that I have is what I see in my IDE and the same has been posted above.

michel-hostettler commented 6 days ago

Are you sure that the following code-snipped points to the right URL of the Grid? new URI("hub:")

So like: new URL("http://localhost:4444") if i run it localy? Because if you have a connection-timeout and you don't see anything in the log of grid or node, it looks like there is absolutely no connection from your application to the grid.

Can you please share the Capabilities witch are in the option on time you create the Remote-Webdriver? And if its possible a little bit more code on top of this code snipped?

nairdinesh04 commented 6 days ago

As I cannot share the IP in the code snippet I have mentioned hub in the snip. "So like: new URL("http://localhost:4444/") if I run it locally?" - this is correct. Just to be clear I am not running hub locally though, so I point to the IP of the hub VM.

The capability in the option is already shared nothing else apart from that.

michel-hostettler commented 6 days ago

What happend if you call this? ( Please change IP)

public static void main(String[] args) throws MalformedURLException { String ip = "localhost"; String port = "4444"; String gridUrl = "http://".concat(ip).concat(":").concat(port); WebDriver driver = new RemoteWebDriver(new URL(gridUrl), new ChromeOptions()); driver.quit(); }

michel-hostettler commented 6 days ago

I think, that your Application does not have access to the Grid or to the port 4444. Are you sure the port is exposed from the Server, the Hub is running on? And is the Server callable without a proxy or something?

nairdinesh04 commented 5 days ago

Yes I think Grid is fine because nodes(other remote VMs) are able to get registered on the node. Let me try running the script from the same machine as grid. I will update the result here.

nairdinesh04 commented 5 days ago

I tried executing code from the same machine where grid is running, but I am seeing the same error.

public static void main(String[] args) throws MalformedURLException { String ip = "localhost"; String port = "4444"; String gridUrl = "http://".concat(ip).concat(":").concat(port); WebDriver driver = new RemoteWebDriver(new URL(gridUrl), new ChromeOptions()); driver.quit(); }

For this if I am not wrong "URL" is deprecated and we will have to use URI.ToUrl() instead.

diemol commented 5 days ago

Can you share the complete Grid logs? Hub and Node.

I dont see any logs on grid command prompt. The only logs that I have is what I see in my IDE and the same has been posted above.

There must be logs, unless you specifically tell the Grid to not log anything. How are you starting the Grid? Can you please check on the Grid machine(s) for the logs when it starts and when the execution is attempted?

nairdinesh04 commented 5 days ago

-----------These are all the logs I see---------------------------------------

C:\Users\user\Downloads>java -jar selenium-server-4.21.0.jar hub (This is how I am starting grid)

00:17:27.550 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding 00:17:27.565 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing 00:17:28.312 INFO [BoundZmqEventBus.] - XPUB binding to [binding to tcp://:4442, advertising as tcp://10.133.48.159:4442], XSUB binding to [binding to tcp://:4443, advertising as tcp://xxxxxx:xxxxxx] 00:17:28.484 INFO [UnboundZmqEventBus.] - Connecting to tcp://xxxxxx:xxxxxxand tcp://xxxxxx:xxxxx 00:17:28.703 INFO [UnboundZmqEventBus.] - Sockets created 00:17:30.015 INFO [UnboundZmqEventBus.] - Event bus ready 00:17:31.531 INFO [Hub.execute] - Started Selenium Hub 4.21.0 (revision 79ed462ef4): http://xxxxxxxxx:xxxxx 00:19:30.979 INFO [Node.] - Binding additional locator mechanisms: relative 00:19:41.910 INFO [Node.] - Binding additional locator mechanisms: relative 00:20:02.112 INFO [Node.] - Binding additional locator mechanisms: relative 00:20:17.758 INFO [Node.] - Binding additional locator mechanisms: relative 00:20:27.879 INFO [Node.] - Binding additional locator mechanisms: relative 00:20:37.935 INFO [Node.] - Binding additional locator mechanisms: relative 00:20:47.974 INFO [Node.] - Binding additional locator mechanisms: relative 00:20:58.012 INFO [Node.] - Binding additional locator mechanisms: relative 00:21:20.903 INFO [Node.] - Binding additional locator mechanisms: relative 00:21:31.523 INFO [Node.] - Binding additional locator mechanisms: relative 00:21:41.537 INFO [Node.] - Binding additional locator mechanisms: relative 00:22:05.061 INFO [Node.] - Binding additional locator mechanisms: relative 00:22:06.255 INFO [GridModel.setAvailability] - Switching Node 55e1baec-0956-4d2f-b2a9-8fcc8c3753ac (uri: http://10.133.48.190:5556) from DOWN to UP 00:22:06.255 INFO [LocalDistributor.add] - Added node 55e1baec-0956-4d2f-b2a9-8fcc8c3753ac at http://xxxxxxx:xxxx. Health check every 120s 00:22:36.955 INFO [Node.] - Binding additional locator mechanisms: relative 00:22:46.990 INFO [Node.] - Binding additional locator mechanisms: relative 00:22:57.716 INFO [Node.] - Binding additional locator mechanisms: relative 00:23:07.756 INFO [Node.] - Binding additional locator mechanisms: relative 00:23:21.117 INFO [Node.] - Binding additional locator mechanisms: relative 01:34:51.970 INFO [Node.] - Binding additional locator mechanisms: relative 01:34:52.458 INFO [GridModel.setAvailability] - Switching Node 8e6f8c61-d1a0-41cb-809e-b4c7b8d3dd7b (uri: http://xxxxxxxxxxxx:xxxx) from DOWN to UP 01:34:52.458 INFO [LocalDistributor.add] - Added node 8e6f8c61-d1a0-41cb-809e-b4c7b8d3dd7b at htto://xxxxxxx:xxxx. Health check every 120s

05:08:54.071 INFO [LocalDistributor.newSession] - Session request received by the Distributor: [Capabilities {browserName: chrome, goog:chromeOptions: {args: [], excludeSwitches: [enable-automation], extensions: []}}] 05:13:54.197 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "ce4880119a96041011b32a8c2f244d67","eventTime": 1719569634190037000,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "localhost:4444","http.method": "POST","http.request_content_length": "291","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.20.0 (java windows)"}}

05:13:54.173 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "bc0d8e3f69fb66d17a0c4c4e1dd5c02c","eventTime": 1719569634163193500,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "localhost:4444","http.method": "POST","http.request_content_length": "291","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.20.0 (java windows)"}}

05:08:54.081 INFO [LocalDistributor.newSession] - Session request received by the Distributor: [Capabilities {browserName: chrome, goog:chromeOptions: {args: [], excludeSwitches: [enable-automation], extensions: []}}] 05:35:50.314 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 9d2f7e2e04675918db5b3c1706d9dc1e Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 126.0.6478.127, chrome: {chromedriverVersion: 126.0.6478.126 (d36ace6122e..., userDataDir: C:\Users\SVC_CM~1\AppData\L...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:54546}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: Windows 10, proxy: {}, se:bidiEnabled: false, se:cdp: ws://10.133.48.159:4444/gri..., se:cdpVersion: 126.0.6478.127, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} 05:35:50.598 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 5edde53b5205cdb2e0d0bc5273be5271 Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 126.0.6478.127, chrome: {chromedriverVersion: 126.0.6478.126 (d36ace6122e..., userDataDir: C:\Users\SVC_CM~1\AppData\L...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:54545}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: Windows 10, proxy: {}, se:bidiEnabled: false, se:cdp: ws://hub:/gri..., se:cdpVersion: 126.0.6478.127, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} 05:35:58.572 INFO [LocalSessionMap.lambda$new$0] - Deleted session from local Session Map, Id: 5edde53b5205cdb2e0d0bc5273be5271 05:35:58.584 INFO [GridModel.release] - Releasing slot for session id 5edde53b5205cdb2e0d0bc5273be5271 05:36:00.641 INFO [LocalSessionMap.lambda$new$0] - Deleted session from local Session Map, Id: 9d2f7e2e04675918db5b3c1706d9dc1e 05:36:00.645 INFO [GridModel.release] - Releasing slot for session id 9d2f7e2e04675918db5b3c1706d9dc1e

nairdinesh04 commented 5 days ago

Not sure why logs are getting stroked out.

nairdinesh04 commented 5 days ago

Strangely I see execution happening in one node machine now. However the tests are running only in one node as of now. Trying to find what's wrong with the other node. Registration is successful though. I will need sometime to debug. We can close this ticket and if needed I will create a separate one. Thank you very much all of you!!

michel-hostettler commented 5 days ago

you are very welcome