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 -->