How to Do Parallel Test Execution In Selenium TestNG Example Program?

Parallel Test Execution TestNg Program: How to Do Parallel Test Execution In Selenium TestNG Example Program?

package com.softwaretestingo.testng;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class ParalleExecutionTest 
{
	@Test
	public void openChrome() throws InterruptedException
	{
		WebDriver driver=new ChromeDriver();
		driver.get("https://demo.softwaretestingo.com/");
		Thread.sleep(3000);
		driver.quit();
	}
	
	@Test
	public void openFirefox() throws InterruptedException
	{
		WebDriver driver=new FirefoxDriver();
		driver.get("https://demo.softwaretestingo.com/");
		Thread.sleep(3000);
		driver.quit();
	}
	
	@Test
	public void openEdge() throws InterruptedException
	{
		WebDriver driver=new EdgeDriver();
		driver.get("https://demo.softwaretestingo.com/");
		Thread.sleep(3000);
		driver.quit();
	}
}

Here is the TestNG XML file

To run parallel, we have two parameters in the XML file “thread-count=”5″ parallel=”methods”. If you want to run Classes parallel then in the place of parallel=”methods” you need to mention parallel=”classes” similarly you can configure for tests also.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="ParalleExecutionTest" verbose='2' thread-count="5" parallel="methods">
  <test thread-count="5" name="ParalleExecutionTest">
    <classes>
      <class name="com.softwaretestingo.testng.ParalleExecutionTest"/>
    </classes>
  </test> <!-- ParalletExecutionTest -->
</suite> <!-- ParalletExecutionTest -->

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

Leave a Comment