Selenium Grid Hub and Node configuration using JSON

Selenium Grid is used to speed up the execution by using multiple machines (multiple browsers with different versions, and browsers running on different operating systems) and run tests in parallel. And also to reduce the time spent for running the test suite after developers check-in their code.

If you just want to get started using selenium grid, you can use simple commands as we discussed in previous article. But if you need more control with advanced configuration, then we have to specify a JSON format config file to configure the hub/node and start it.

As said, hub/node can be configured in 2 different ways, one is by specifying command line parameters, and the other way is by specifying a json file which we are going to see here.

Configuring hub using below 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

This is a sample hubconfig.json file which was made available by Selenium. You can also download this file.

Start hub using below command :-

java -jar selenium-server-standalone-3.x.x.jar -role hub -hubConfig hubconfig.json

In our case, we used selenium latest version 3.4.0 and changed the json file name to 'gridHubConfig.json'. You can also change the json file name if needed. No other changes are made.

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

Selenium grid console

Now open your browser and enter the URL either with IP address or localhost with port number. In our case it was with - http://xx.xx.xx.106:4444/grid/console or http://localhost:4444/grid/console

You should see something like below, which indicates Grid configured successfully and is Up and running

Selenium grid console

Configuring nodes using below 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": {}

There is a sample nodeconfig.json file which was made available by Selenium. You can also download node file.

If you see above config file, we have not added 'host' parameter, though it is not mandatory but if you are trying to add multiple nodes from different machines, make sure to specify -remoteHost or -host with ip which you want to use.

If not specified, when the node starts, it tries to guess the ip address of the host machine. If there several network interfaces, the guessing can return the wrong address and will return error as DefaultRemoteProxy unknown version, connect to :port [/] failed: Connection timed out

If you are still using Selenium version 2.x.x, then you should download and use version 2.x.x nodeconfig file as the configuration { ... } object in version 2.x.x has been removed in version 3.x.x

Start node using below command :-

Before starting the below command, we need to make sure the driver executable are downloaded and available on node machines. As we need to set the path to driver executable while starting the nodes via command line. If the executable are in the some other directory, you have to pass ABSOLUTE_PATH of the driver executable

java"chromedriver.exe""IEDriverServer.exe" -Dwebdriver.gecko.driver="geckodriver.exe" -jar selenium-server-standalone-3.4.0.jar -role node -nodeConfig node1.json

Selenium node config command

Now open your grid console, either with - http://xx.xx.xx.106:4444/grid/console or http://localhost:4444/grid/console

You should see something like below, which indicates node successfully registered with grid

Selenium grid console with nodes

If you just want to execute your tests on only Firefox and Chrome browser, we can remove IE capabilities from the json and then we don't have to pass IE driver executable.

java"chromedriver.exe" -Dwebdriver.gecko.driver="geckodriver.exe" -jar selenium-server-standalone-3.4.0.jar -role node -nodeConfig node1.json

All the -D arguments in the command line should come before the '-jar' as Java command line usage requires system properties to be specified before the -jar. If not the you may see an exception as "Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option:"

Note: If you are using selenium version 2.x.x, you don't have to pass geckodriver. Geckodriver is only needed when using selenium 3.x.x.

If you want to check list of configuration properties in detail for Selenium hub/node, run below commands

java -jar selenium-server-standalone-3.x.x.jar -role hub -help
java -jar selenium-server-standalone-3.x.x.jar -role node -help

When you are trying to launch selenium hub/node on java 1.7 using Selenium 3.x.x, you may see an exception like below, In this case you have to upgrade your JDK from Java 7 to Java 8 or higher version.
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/grid/selenium/GridLauncherV3

Hope this helps you to configure selenium grid using Json files.

Selenium Tutorials: 


Thanks for the detailed steps. I have configured hub and nodeconfig.json as you mentioned. I have taken hub and node same machine then i ran successfully. But when configured node on other machine i am getting "hub is down or not responding connection timed out". I have placed nodeconfig.json in node machine only. am i need to place this nodeconfig.json in hub machine also?

did you change the ip when you moved the node to a remote machine. It still might be pointed to the localhost

What is the logging parameter for Selenium 3.4.0.
-log "logname" is not working with this version.

That was very useful :)

Could you please tell me why this configuration is not working in Selenium 4

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.