Run Test cases by using Selenium Grid

In the previous post, we have seen how to configure hub and node by using Json file. In this post, we will see how to run test cases by using Selenium Grid.

We have already seen how to start the hub and node. We assume that Hub is up and running. Let’s start a node by using below command.

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

Node started in grid


Writing program:

You need to use DesiredCapabilities  to set the browser and platform where the test cases will be executed. We have to use RemoteWebDriver to invoke the browser instance. This accepts the url (Selenium Grid web interface) and capabilities as its arguments. 

In one of the class, we are opening Gmail application and another class will open Facebook. Let’s see the code of the classes.

First Class:

Second Class:

testng.xml used to run both the classes:

Observe the keyword parllel=”tests” in testng.xml, which is used to run test cases parallel.In our case, it has opened one firefox and one chrome browser instance. It picks up the browser randomly depending on the availability.


Selenium Grid tests

Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum


Configure node by using JSON file
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...