top of page

A Detailed Guide to Reduce Run-time Using Parallel Testing in Selenium



Parallel testing is a process where multiple tests are executed simultaneously/in parallel in different thread processes. With respect to Selenium, it allows you to execute multiple tests on different browsers, devices, environments in parallel and at the same time, instead of running it sequentially.

With Parallel Testing, automated tests can be run in parallel or concurrently across various test environments of different device/browser/Operating System versions and their combinations. Hence more tests are run at a time which reduces the execution time by many folds.

Less execution time implies a less wait and fast build releases thus reducing the overall testing time required!

Benefits of Parallel Testing

  • Test for Wider Compatibility

  • Parallel Testing Optimizes Continuous Integration and Delivery

  • Saves time and improves productivity

  • Better coverage of tests

  • Can Radically Reduce Feedback Time

How do you perform parallel testing with TestNG?

TestNG allows running the tests in parallel by setting the “parallel” attribute in the “<suite>” tag respectively to “tests”, “methods”, “classes”, “instances”. As per the setting provided to run the tests, it will start executing the tests in separate threads.

The goal of parallel testing is to resolve the constraints of time by distributing tests across available resources. For example, if 20 test cases take a total of 100 minutes to complete, then 10 parallel executions could run 2 test cases each and bring the total testing time down to 10 minutes.

Parallel testing accepts the following keywords (values) in TestNG:

  • Methods: This will run the parallel tests on all @Test methods in TestNG.

  • Tests: All the test cases present inside the <test> tag will run with this value.

  • Classes: All the test cases present inside the classes that exist in the XML will run in parallel.

  • Instances: This value will run all the test cases parallelly inside the same instance.

Example for Parallel Testing

This example has three files created as a Maven Project.


ii) Pom.xml

iii) Testng.xml

Note: We can use either if else block or switch case to select different browsers

package BrowserTypes;
 import java.util.concurrent.TimeUnit;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.edge.EdgeDriver;
 import org.openqa.selenium.firefox.FirefoxDriver;
 import org.testng.annotations.AfterTest;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Parameters;
 import org.testng.annotations.Test;

 public class ParallelScript {
 WebDriver driver;
 public void setup(String browser) throws Exception{
  System.out.println("Browser Name is :" + browser);
   driver = new FirefoxDriver();
  else if(browser.equalsIgnoreCase("chrome")){
    driver = new ChromeDriver();
  else if(browser.equalsIgnoreCase("Edge")){
   driver = new EdgeDriver();
   throw new Exception("Browser is not correct");

  switch(browser.toUpperCase()) {
  case "FIREFOX":
   driver=new FirefoxDriver();
  case "CHROME":
   driver = new ChromeDriver();
  case "EDGE":
   driver=new EdgeDriver();
   System.out.println("Browser is not correct");
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 public void testParameterWithXML() throws InterruptedException{
  WebElement userName = driver.findElement("uid"));
  WebElement password = driver.findElement("password"));
  System.out.println("Test completed Successfully");
 public void browserQuit() {



In this file, we add all the necessary plugins and dependencies

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">


<!-- -->
<!-- -->
<!-- -->

<!-- -->



Since we are using TestNG Parameters in, we need to specify the values from the TestNG.XML file that will pass to the test case file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="Suite" thread-count="3">
<test name="ChromeTest">
<parameter name="browser" value="Chrome" />
<class name="BrowserTypes.ParallelScript">
  <test name="FirefoxTest">
<parameter name="browser" value="Firefox" />
<class name="BrowserTypes.ParallelScript">
<test name="EdgeTest">
<parameter name="browser" value="Edge" />
<class name="BrowserTypes.ParallelScript">
</suite> <!-- Suite -->

Here because the testing.xml has three Test tags (‘ChromeTest’,’FirefoxTest’,’EdgeTest’),this test case will execute simultaneously on 3 different browsers.

In the testing.xml, we set the parallel attribute to “tests” in testing.xml, to perform parallel testing.

Note: To run the test, Right click on the testing.xml, Select Run As, and Click TestNG


Test Run Time Comparison

Below is the console output if we run the testing.xml

If we check refresh the project on left panel, test-output folder is created. You can find the file. It shows the total run time of the tests.

Below is the index report showing test run time, we get if remove ‘Parallel=”tests”’ from the testing.xml file

If you see the Results of running suite, the total time taken for parallel testing is 7186 ms whereas in normal testing,it is 12085 ms. When we run large volume of test cases, parallel execution reduces test execution time significantly.

Advantages of Parallel Testing

To summarize, parallel testing has the following advantages:

  • Reduces Time: Running the tests in parallel reduces the overall execution time.

  • Allow Multi-Threaded Tests: Using the parallel execution in TestNG, we can allow multiple threads to run simultaneously on the test case providing independence in the execution of different components of the software.

Disadvantages of Parallel Testing

At the same time, parallel testing in TestNG also has some disadvantages as below:

  • Fails On Dependent Modules: Parallel testing allows independent running of modules simultaneously. Due to this, we cannot go ahead with modules that are dependent on each other, and this occurs quite frequently while testing. So, either we run serially or remove dependence, which takes extra time and effort.

  • Knowledge Of Program Flow: The tester should have good knowledge with the flow of the program to create parallel testing modules. A slight interdependency can bring down the whole test case execution. The tester should also know which modules to run in multiple threads and which ones to run in the same threads etc.


Parallel testing in TestNG using Selenium helps us to deliver the projects at a faster rate in agile and continuous delivery working environment, which is challenging in its way.

Thus, you would have got an idea of Parallel Test Execution in Selenium. Happy Testing!!!

1,529 views0 comments

Recent Posts

See All


Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page