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


Dwarika Dhish Mishra

My name is Dwarika Dhish Mishra, its just my name and I am trying to bring the worth of my name in to actions and wants to be the solution not the problem. I believe in spreading knowledge and happiness. More over I am fun loving person and like travelling a lot. By nature I am a tester and a solution maker. I believe in the tag line of http://ted.org “Idea worth spreading” . For the same, I have created this blog to bring more and more learning to tester fraternity through day to day learning in professional and personal life. All contents are the part of my learning and so are available for all..So please spread the contents as much as you can at your end so that it could reach to every needful people in testing fraternity. I am pretty happy that more and more people are showing interest to become the part your Abode QA blog and I think this is good sign for us all because more and more content would be before you to read and to cherish. You may write or call me at my Email id: dwarika1987@gmail.com Cell: 9999978609

You may also like...

2 Responses

  1. Shama Ugale says:

    Hi,

    Here if i try changing the port from 5555 to say 6000, in the node.json file , it still picks up 5555 and i get an error as i have already been running a node on 5555.
    Is there any other way where in i can change the port in the json file it reflects .

    Whereas if i pass the port in command line along with the json file it works
    like
    1
    java -jar selenium-server-standalone-3.0.0-beta3.jar -role node -nodeConfig Node1.json -port 8888

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.