Configuring Selenium Grid – How to setup in a easy way

Recently I had to configure a Selenium Grid but could not find something really running on the WEB. So a decided to do it myself and post here something that really works.

The job is divided in two parts:
1) Configure the HUB
2) Configure each one of the nodes.

Configuring the HUB
Create a Json file and name it Config1.json

To start the hub, run this in the windows command line (CMD)

java -jar c:\grid\selenium-server-standalone-3.7.1.jar -role hub -hubConfig c:\grid\hubConfig1.json

Configuring a NODE

For each node, also have a Json file, like this one:

The command line will be:

java -Dwebdriver.chrome.driver="c:\grid\chromedriver.exe" -jar c:\grid\selenium-server-standalone-3.7.1.jar -role node -nodeConfig nodeChrome.json

Things to be sure:
* Always keep your files update because as a new browser version appears, you need new drivers (usually)
* The values used in the Json files need to match when you create an instance in your program.

Example how to create a driver and attach to the remote driver at port 5555:

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
...
dc = DesiredCapabilities.chrome();
dc.setBrowserName("Chrome");
dc.setPlatform(Platform.WIN10);
Webdriver driver = new RemoteWebDriver(http://localhost:5555, dc);

Note:
* Edge driver has a build version that should match your windows build version. When downloading it, pay attention to this detail.

Your grid folder will be like:

In startGrid.bat, I have all the necessary commands to start the HUB and the nodes:


start /b java -jar c:\grid\selenium-server-standalone-3.7.1.jar -role hub -hubConfig c:\grid\hubConfig1.json
start /b java -Dwebdriver.gecko.driver="c:\grid\geckodriver.exe" -jar c:\grid\selenium-server-standalone-3.7.1.jar -role node -nodeConfig nodeFF.json
start /b java -Dwebdriver.chrome.driver="c:\grid\chromedriver.exe" -jar c:\grid\selenium-server-standalone-3.7.1.jar -role node -nodeConfig nodeChrome.json
start /b java -Dwebdriver.ie.driver="c:\grid\IEDriverServer.exe" -jar c:\grid\selenium-server-standalone-3.7.1.jar -role node -nodeConfig c:\grid\nodeIE.json
start /b java -Dwebdriver.edge.driver="c:\grid\MicrosoftWebDriver.exe" -jar c:\grid\selenium-server-standalone-3.7.1.jar -role node -nodeConfig c:\grid\nodeEdge.json

Use this as a template for you nodes Json files.
Change browsername and port. In my hub I have FF in port 5555, Chrome in port 5556, etc…

{
"capabilities":
[
{
"browserName": "firefox",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}

],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 20,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4445",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}

* To see if you HUB is working, go to http://localhost:4445
* To see if your node is working, go to http://localhost:5555 and click on Create Session. Select the browser and see if it loads.

Mauro.

Leave a Reply

Your email address will not be published. Required fields are marked *

*