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.

Output:

Selenium Grid tests


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

 

Print Friendly, PDF & Email
Configure node by using JSON file
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...