Author - StudySection Post Views - 65 views
Parallel test Selenium

Parallel Test Execution using Selenium TestNG

Parallel testing is a process of running the test cases or modules simultaneously rather than consecutively on different threads. The TestNG framework allows us to execute multiple test cases parallel over different environments instead of running test cases one after another. It helps to reduce the testing time and effort.

TestNG provides different ways to execute tests in separate threads by using the parallel attribute in the testng.xml file. Where we can set the parallel attribute to method, tests, and classes.
<suite name="Suite" parallel = "methods">...</suite>
Here, all the methods with Test annotation will execute parallel.

The parallel test attribute can accept only four values:

  1. Tests – All the tests inside the test tag will run parallel.
  2. Classes – All the tests inside a java class will run parallel.
  3. Methods – All the methods with test annotation will execute parallel.
  4. Instances – Tests in the same instance will execute parallel.

Example: Here is an example of a webner solutions website that will execute on different browsers simultaneously and check the loading time.

package TA;
import org.apache.commons.lang3.time.StopWatch;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class ParallelExcution {
WebDriver driver;
public void googleChrome() {
driver = new ChromeDriver();
public void mozillaFirefox() {
driver = new FirefoxDriver();
public void edge() {
driver = new EdgeDriver();
public void URL() {
StopWatch pageLoad = new StopWatch();
long pageLoadTime = pageLoad.getTime()/1000;
System.out.println(pageLoadTime + "seconds");

XML File:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="Suite" parallel = "methods">
<test thread-count="10" name="Test">
<class name="TA.ParallelExcution"/>
</test> <!-- Test -->
</suite> <!-- Suite -->


People having good command over the French language can get a French certification from StudySection. StudySection offers both beginner level and expert level French Certification Exams to test the ability to communicate in the French language.

Leave a Reply

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