Set Up Selenium Grid for Parallel Run

Run your test suite on multiple machines against different browsers in parallel is always a tempting idea and Selenium-Grid makes it feasible. Running your tests in a distributed test execution environment is no more a dream!

Grid Architecture

Selenium Grid consists of 2 type of components:

  • A single HUB: acts as a controller of the grid
  • and one or more nodes: Actual tests are run on these node machines

It looks like this:

Figure 1: Selenium Grid

How test script talks to Hub
Our test script will connect to Hub using hub’s host name and port, and sends all the commands of our test cases to the hub. It is up to HUB to decide what test cases will be run on which node machine.

How Hub communicates with Nodes
First a node will register itself with Hub, telling Hub what OS it is and what browsers are installed on itself. Based on these info, Hub will later on match test cases with suitable node machine for actual run.

All machines in the grid, both hub and nodes, need to download selenium Server jar for normal operation.

Configure Hub

1. What to configure?
Port: Our test script will have to talk AKA connect to Hub, and we need to know the host name of HUB and the port we can use in order to connect to it.
Timeout: browserTimeout, newSessionWaitTimeout etc.
Servlet-related configurations: Selenium Grid allows you to plug in 3rd party servlets, and there are some configuration items for this.

The default port Hub is using is 4444. You can change it to some other port if needed.
All other configurations are optional, and will use default values if not specified.

2. How to configure
We can configure hub via command line parameters when we start it up:

// specify port as parameter
java -jar selenium-server-standalone.jar -role hub -port 4441

Or we can use a json configuration file hubConfig.json:

“port”: 4444,
“newSessionWaitTimeout”: -1,
“servlets” : [],
“withoutServlets”: [],
“custom”: {},
“capabilityMatcher”: “org.openqa.grid.internal.utils.DefaultCapabilityMatcher”,
“throwOnCapabilityNotPresent”: true,
“cleanUpCycle”: 5000,
“role”: “hub”,
“debug”: false,
“browserTimeout”: 0,
“timeout”: 1800

And then start up Hub by specifying json file

java -jar selenium-server-standalone.jar -role hub -hubConfig hubConfig.json

Configure Nodes

1. What can be configured?
We can specify what browsers on this node will be available for the Grid to use
We can specify how many maximum instances of specific browsers are allowed to run at the same time
We can specify proxy info of the browser is any

2. How to configure
Similar to Hub configure, 2 ways to configure a node: via parameters in command or via json config file.
via parameters in command

java -jar selenium-server-standalone-3.5.3.jar -role node -hub http://HUBhostName:4444/grid/register

via json config file (Goto for more info):

java -jar selenium-server-standalone.jar -role node -nodeConfig nodeconfig.json

A sample nodeconfig.json:

“browserName”: “firefox”,
“maxInstances”: 5,
“seleniumProtocol”: “WebDriver”
“browserName”: “chrome”,
“maxInstances”: 5,
“seleniumProtocol”: “WebDriver”
“browserName”: “internet explorer”,
“maxInstances”: 1,
“seleniumProtocol”: “WebDriver”
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“maxSession”: 5,
“port”: 5555,
“register”: true,
“registerCycle”: 5000,
“hub”: “http://localhost:4444”,
“nodeStatusCheckTimeout”: 5000,
“nodePolling”: 5000,
“role”: “node”,
“unregisterIfStillDownAfter”: 60000,
“downPollingLimit”: 2,
“debug”: false,
“servlets” : [],
“withoutServlets”: [],
“custom”: {}

Grid Console

You can view grid state on hub machine. Just navigate in any browser on hub:
http://localhost:4444 or

You will see the console like this:

Figure 1: Grid Console

The console page displays Node Machine IP Address, OS Type, Browsers etc on the screen. When new node is added into grid, refresh this console you will see newly added node info.

Click on ‘View Configure’ link or Configuration tab, the details of hub and nodes configuration will be displayed.