WebDriverError: Error forwarding the new session Error forwarding the request Operation timed out

31 Views Asked by At

I'm encountering the following error when trying to run my selenium testcase using selenium grid. It's really just a modified selenium example from their docs. ChromeDriver is 123.0.6312.58 Chrome is 123.0.6312.59 (Although I don't know if selenium is using this chrome)

const {By, Builder, Browser, until} = require('selenium-webdriver');
const assert = require("assert");

const chrome = require('selenium-webdriver/chrome');

const chromeDriverPath = '/usr/local/bin/chromedriver';
const options = new chrome.Options();
options.addArguments("--remote-allow-origins=*");
options.setChromeBinaryPath(chromeDriverPath);

(async function firstTest() {
  let driver;
  
  try {
    driver = await new Builder().forBrowser(Browser.CHROME).setChromeOptions(options).usingServer('http://localhost:4444/wd/hub').build();

    await driver.get('https://www.selenium.dev/selenium/web/web-form.html');
    let title = await driver.getTitle();
    assert.equal("Web form", title);
  
    await driver.manage().setTimeouts({implicit: 500});
  
    let textBox = await driver.findElement(By.name('my-text'));
    let submitButton = await driver.findElement(By.css('button'));
  
    await textBox.sendKeys('Selenium');
    await submitButton.click();
  
    let message = await driver.findElement(By.id('message'));
    let value = await message.getText();
    assert.equal("Received!", value);
  } catch (e) {
    console.log(e)
  } finally {
    await driver.quit();
  }
}())

I'm using selenium-webdriver 3.6.0. I'm trying to run this with selenium grid. I ran the command java -jar selenium-server-standalone-3.6.0.jar -role hub to start the hub and java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar selenium-server-standalone-3.6.0.jar -role node -hub http://localhost:4444 to start the node.

The hub and node started successfully and logged as follows: hub:

19:26:01.508 INFO - Selenium build info: version: '3.6.0', revision: '6fbf3ec767'
19:26:01.508 INFO - Launching Selenium Grid hub
2024-03-27 19:26:01.924:INFO::main: Logging initialized @551ms to org.seleniumhq.jetty9.util.log.StdErrLog
19:26:01.929 INFO - Will listen on 4444
2024-03-27 19:26:01.958:INFO:osjs.Server:main: jetty-9.4.5.v20170502
2024-03-27 19:26:01.970:INFO:osjs.session:main: DefaultSessionIdManager workerName=node0
2024-03-27 19:26:01.970:INFO:osjs.session:main: No SessionScavenger set, using defaults
2024-03-27 19:26:01.971:INFO:osjs.session:main: Scavenging every 660000ms
2024-03-27 19:26:01.975:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@5e3f861{/,null,AVAILABLE}
2024-03-27 19:26:01.985:INFO:osjs.AbstractConnector:main: Started ServerConnector@4c5ae43b{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2024-03-27 19:26:01.985:INFO:osjs.Server:main: Started @613ms
19:26:01.986 INFO - Nodes should register to http://10.32.40.97:4444/grid/register/
19:26:01.986 INFO - Selenium Grid hub is up and running
19:26:03.717 INFO - Registered a node http://10.32.40.97:5555
19:26:23.738 INFO - Marking the node http://10.32.40.97:5555 as down: cannot reach the node for 2 tries
19:27:23.770 INFO - Unregistering the node http://10.32.40.97:5555 because it's been down for 60032 milliseconds
19:27:23.770 WARN - Cleaning up stale test sessions on the unregistered node http://10.32.40.97:5555

node:

19:22:38.069 INFO - Selenium build info: version: '3.6.0', revision: '6fbf3ec767'
19:22:38.070 INFO - Launching a Selenium Grid node
2024-03-27 19:22:38.275:INFO::main: Logging initialized @343ms to org.seleniumhq.jetty9.util.log.StdErrLog
19:22:38.292 INFO - Driver class not found: com.opera.core.systems.OperaDriver
19:22:38.301 INFO - Driver provider class org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
 registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform MAC
19:22:38.301 INFO - Driver provider class org.openqa.selenium.edge.EdgeDriver registration is skipped:
 registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform MAC
19:22:38.311 INFO - Using the passthrough mode handler
2024-03-27 19:22:38.320:INFO:osjs.Server:main: jetty-9.4.5.v20170502
2024-03-27 19:22:38.331:WARN:osjs.SecurityHandler:main: [email protected]@687ef2e0{/,null,STARTING} has uncovered http methods for path: /
2024-03-27 19:22:38.333:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@687ef2e0{/,null,AVAILABLE}
2024-03-27 19:22:38.341:INFO:osjs.AbstractConnector:main: Started ServerConnector@6ad59d92{HTTP/1.1,[http/1.1]}{0.0.0.0:5555}
2024-03-27 19:22:38.341:INFO:osjs.Server:main: Started @409ms
19:22:38.341 INFO - Selenium Grid node is up and ready to register to the hub
19:22:38.347 INFO - Starting auto registration thread. Will try to register every 5000 ms.
19:22:38.347 INFO - Registering the node to the hub: http://localhost:4444/grid/register
19:22:38.354 INFO - The node is registered to the hub and ready to use

And then the output from my selenium script

node test.js
WebDriverError: Error forwarding the new session Error forwarding the request Connect to 10.32.40.97:5555 [/10.32.40.97] failed: Operation timed out
    at Object.checkLegacyResponse (/Users/zakjonat/seleniumStackOverflow/node_modules/selenium-webdriver/lib/error.js:546:15)
    at parseHttpResponse (/Users/zakjonat/seleniumStackOverflow/node_modules/selenium-webdriver/lib/http.js:509:13)
    at /Users/zakjonat/seleniumStackOverflow/node_modules/selenium-webdriver/lib/http.js:441:30
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
From: Task: WebDriver.createSession()
    at thenableWebDriverProxy.createSession (/Users/zakjonat/seleniumStackOverflow/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
    at thenableWebDriverProxy.createSession (/Users/zakjonat/seleniumStackOverflow/node_modules/selenium-webdriver/chrome.js:761:15)
    at createDriver (/Users/zakjonat/seleniumStackOverflow/node_modules/selenium-webdriver/index.js:170:33)
    at Builder.build (/Users/zakjonat/seleniumStackOverflow/node_modules/selenium-webdriver/index.js:626:16)
    at firstTest (/Users/zakjonat/seleniumStackOverflow/test.js:21:131)
    at Object.<anonymous> (/Users/zakjonat/seleniumStackOverflow/test.js:54:2)
    at Module._compile (node:internal/modules/cjs/loader:1267:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
    at Module.load (node:internal/modules/cjs/loader:1125:32)
    at Module._load (node:internal/modules/cjs/loader:965:12) {
  remoteStacktrace: ''
}
/Users/zakjonat/seleniumStackOverflow/test.js:52
    await driver.quit();
                 ^

TypeError: Cannot read properties of undefined (reading 'quit')
    at firstTest (/Users/zakjonat/seleniumStackOverflow/test.js:52:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.0.0

Any help is appreciated!

1

There are 1 best solutions below

1
jayachandran On

Just a suggestion. If you use selenium v4.6+ You don't need chrome drivers. Selenium released Selenium Manager which can get all the browser drivers automatically. You have to remove the environment variable and chrome drivers from your machine and update to selenium v4.6+ then you don't have to worry about drivers.