top of page

Varied understanding of TestNg and Selenium grid on distinct lines.

  • Writer: khyati sehgal
    khyati sehgal
  • Aug 31, 2014
  • 3 min read

Last week, I have given a session over the Selenium grid with one of my colleagues. 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 the user has a 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();
capabilities.setBrowserName("firefox");
RemoteWebDriver driver = null;
try{
driver= new RemoteWebDriver(new URL("http:/<hub-ip>:<hub-port>/wd/hub/"),capabilities);
}
catch(MalformedURLException e){
e.printStackTrace();
}
driver.get("http://google.com");
}
 

This is one sample request, and you can add different types 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 that we can directly apply to our tests. Along with this, it makes 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

DevTools listening on ws://127.0.0.1:57284/devtools/browser/f4efc932-01f3-4ac5-8a77-b19e65f2849b
 [14:36:42] E/launcher - session not created: Chrome version must be between 70 and 73
   (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)
 [14:36:42] E/launcher - SessionNotCreatedError: session not created: Chrome version must be between 70 and 73
   (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)
     at Object.checkLegacyResponse (C:\Users\khyati.sehgal\source\Workspaces\QA\SAND-DEV-1\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:546:15)
     at parseHttpResponse (C:\Users\khyati.sehgal\source\Workspaces\QA\SAND-DEV-1\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
     at doSend.then.response (C:\Users\khyati.sehgal\source\Workspaces\QA\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:441:30)
     at 

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

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 the Selenium grid and TestNg capabilities.

Comments


bottom of page