Selenium, Selenium grid, Testing, TestNG

Varied understanding of TestNg and Selenium grid on distinct lines.

Last week, I have given a session over Selenium grid with one of my colleague. In that session, we have covered various topic related to Selenium grid, and we answered some great questions which were asked from the audience out there. In this blog post, I will share the most relish topic which is TestNG.

I have seen many articles, notes, etc over the comparison of TestNG and Selenium Grid, and in this piece of write-up I will share my own experience of working with both and what all pros-cons both holds.To start with let us start with Selenium grid.

Selenium Grid

It is one of the flavor of widely used web automation tool – Selenium. Selenium comes in different edition, like Selenium IDE, Selenium Remote Control, Selenium Webdriver, and Selenium Grid. Each one has its own unique importance.

Why Selenium Grid?

Selenium grid offers unique inclination towards multiple runs, So if I have to distinguish from a high level then it is widely used when user has requirement where-in he has to run multiple tests parallel having different capabilities. By capabilities I mean different Operating Systems, Programming language, Browser, etc.

  • Simple java example to kick start Selenium grid

Pre-requisite to run the below code

  1. You need yo start a hub at your local/or some remote machine,and mention the hub-ip and hub-port in the URL location.
  2. You need to start nodes at multiple machines. (NOTE: You can start node at single machine also for that you need to make sure that the port should be unique for all the nodes, but it is advised not to do so ,as it can result in major CPU hit.)
  3. You should have eclipse at your local, along with the selenium-standalone-jar.
  4. Make sure you have added this jar to the project -build path.

public class UsingSeleniumGridWithFireFox {
public static void main(String[] args) {
DesiredCapabilities capabilities = new DesiredCapabilities();
RemoteWebDriver driver = null;
driver= new RemoteWebDriver(new URL("http:/<hub-ip>:<hub-port>/wd/hub/"),capabilities);
catch(MalformedURLException e){

This is one sample request, and you can add different type of tests like this which would be running on different capabilities like IE, Chrome, Opera, Andriod, etc. Once you are done making a test suite having, say 20, tests running parallel-y you are done with Selenium grid set up. Like this:

  1. QuickTestWinFF
  2. QuickTestWinFF2
  3. QuickTestLinuxFF
  4. QuickTestWinFF2
  5. QuickTestWinFF3
  6. QuickTestWinFF5
  7. QuickTestWinFF4
  8. QuickTestWinChrome

Where is TestNG then?

TestNG is a unit testing framework, and it offers varied annotations which we can directly apply on our tests. Along with this it make oneself available with a remarkable power of parallel runs.

Let us see, how can we club Selenium grid and TestNg proficiency

When you are working with TestNG, the each project which is TestNg-fied has a testng.xml file which drives the whole flow of work. Now lets take a deeper look how we can actually implement this.

A testng.xml file having detail of all the tests

<!DOCTYPE suite SYSTEM "" >
<suite name="Test Suite" verbose="1" parallel="tests" thread-count="6">
<test name="Windows / Firefox">
<class name="com.seleniium.parallel.QuickTestWinFF" />
<test name="Windows / Firefox2">
<class name="com.seleniium.parallel.QuickTestWinFF2" />
<test name="Linux / Firefox">
<class name="com.seleniium.parallel.QuickTestLinuxFF" />
<test name="Windows / Firefox3">
<class name="com.seleniium.parallel.QuickTestWinFF3" />
<test name="Windows / Firefox4">
<class name="com.seleniium.parallel.QuickTestWinFF4" />
<test name="Windows / Firefox5">
<class name="com.seleniium.parallel.QuickTestWinFF5" />
<test name="Windows / Firefox6">
<class name="com.seleniium.parallel.QuickTestWinFF6" />
<test name="Windows / Chrome">
<class name="com.seleniium.parallel.QuickTestWinChrome" />
</test><!-- <test name="Internet Explorer"> <parameter name=""
value="localhost"></parameter> <parameter name="selenium.port" value="5557"></parameter>
<parameter name="selenium.browser" value="*iehta"></parameter> <parameter
name="selenium.url" value=""></parameter> <parameter
name="searchCriteria" value="TestNG"></parameter> <classes> <class name="com.qaselenium.NewTest"/>
</classes> -->

 What this testNg.xml is doing?

This is actually telling the executor which test cases of the project to run, when user runs the project with TestNg.xml.

And these would be the specifications of the tests-run:

  1. Run all tests mentioned in <test> <classes> </classes></tests> tags.
  2. Run them on the mentioned capabilities.
  3.  Skip those tests which are not mentioned in the testNg.xml.
  4. Run tests such that the tests should in parallel and in multiple-processing mode.

Why to use TestNG, if Selenium grid is doing everything?

According to my experience, Selenium Grid is used for infra-structure set up and TestNG is required for actual execution.

That is how you can run your tests multiple at a time and parallel-y by using Selenium grid and TestNg capabilities.


1 thought on “Varied understanding of TestNg and Selenium grid on distinct lines.”

  1. I am no longer certain where you are getting your information, but good topic. I needs to spend some time learning more or understanding more. Thanks for fantastic information I was looking for this information for my mission.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s