Selenium Grid Tutorial: running hub and nodes using json

Selenium Grid Tutorial: running hub and nodes using json

Selenium Grid Tutorial: running hub and nodes using json

This post is just the continuation of last two post

    1. Selenium Grid Tutorial : Setting up hub and node

IT Certification Category (English)728x90

  1. Playing with node registration parameters in grid

In these two post, we have learned how to launch hub and node using a command line and have also seen how to use parameters efficiently. But in this post, we are going to see how to use JSON files to run your hub and nodes.
Steps:



1- We need to create json file for hub and node. Now we are going to see the json that is needed for hub. a) Open any text editor like notepad or textedit. b) Past content in editor from JSON for Hub code block. c) Save this with hub.json in same place where you have your selenium-server-standalone jar file JSON for Hub

{
  "host": null,
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "prioritizer": null,
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "throwOnCapabilityNotPresent": true,
  "nodePolling": 5000,

  "cleanUpCycle": 5000,
  "timeout": 300000,
  "browserTimeout": 0,
  "maxSession": 5,
  "jettyMaxThreads":-1
}
you can fine it at this place. In the same fashion we can create json file for node and this would look like this, In this we are going to give value for browserName, version and platform as well in this json file and will save it as node.json JSON for node
{
  "capabilities":
      [
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "version": "3.6",
          "platform": "WINDOWS"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5555,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": "ip"
  }
}
above json has been divided in two part first part takes all the parameter that we can set using desiredcapabilities for any browser and second section contains all the configuration related stuff. IT Certification Category (English)728x90 2- Once we are done with hub and node json file creation.Follow the following steps to run hub and node Hub: 1- Open CMD/terminal, navigate to the place where the selenium-server-standalone jar is present. 2- Type following command
java -jar selenium-server-standalone-2.48.2.jar -role hub -hubConfig hub.json
and hit enter it will start your hub and to check this go to http://localhost:444/grid/console. Selenium grid console So if you have gone through previous post then you would come to know that -hubConfig is new parameter that is being followed by the json file that has been created for hub. Node: 1- As we have seen in case of hub, we need to open cmd/terminal and need to navigate to location of selenium-server-standalone jar 2- Run following command
java -jar selenium-server-standalone-<version>.jar -role node -hub http://IP:4444/grid/register -nodeConfig node.json
above command would register node with hub and all browser instances and session detail would be present in node.json. This can be seen on http://localhost:4444/grid/console Selenium Grid Console with port parameter