Parallel execution of Tests in TestNG

How we can achieve running of parallel set of tests in TestNG.

Parallel run in Selenium
Parallel Run

We are already done with cross browser testing using TestNG, we would utilize the same example here to design our solution.

Test Scenario:-
We want parallel instances of Test Case one in Firefox and another in Chrome, but with different set of data.
Firefox with ‘username1’ and ‘password1’
Chrome with ‘username2’ and ‘password2

We would use the @parameter annotation to create different set  of data.
Also we would add,’Parallel’ attribute in the Suite tag of XML file, this  is being used to run tests parallel in different browsers.
And ‘thread-count’ attribute is to used to pass the number of maximum threads to be created.

XML File:-

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="tests" thread-count="2">
<test name="Run in Firefox">
<parameter name="browser" value="firefox"></parameter>
<parameter name="userName" value="Test1"></parameter>
<parameter name="Password" value="Pwd1"></parameter>
<class name="srcTest.ParallelTesting"/>
<test name="Run in chrome">
<parameter name="browser" value="chrome"></parameter>
<parameter name="userName" value="Test2"></parameter>
<parameter name="Password" value="Pwd2"></parameter>
<class name="srcTest.ParallelTesting"/>

Java Code:-

package srcTest;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class ParallelTesting {
private WebDriver driver;
public void login(String userName,String Password)
//Adding Implicit wait
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Maximize browser
//Open the Login Application
//Fill the UserName and Password fields
//Click the Sign in Button
//Clicking on the alert message


public void BeforeClass(String browser) throws Exception {
//Incase it is firefox browser
driver = new FirefoxDriver();
//Incase browser is chrome
else if(browser.equals("chrome"))
System.setProperty("", "D:\Automation\Selenium\MyCode\chromedriver_win32\chromedriver.exe");
driver = new ChromeDriver();
//Exit the Test without execution
//Throw an exception for no matching browsers
throw new Exception("Invalid Browser"+browser);


public void afterClass() {
//Destroying the object


More Testing Scenarios


One thought on “Parallel execution of Tests in TestNG

  1. This is not working Parallel, Its Failing on Chrome Browser. Username & Password values are entered in FF only, Chrome browser, not able to enter Username & Password, so following error displayed.
    org.openqa.selenium.NoAlertPresentException: no alert open

Leave a Reply

Your email address will not be published. Required fields are marked *