What is Parallel Execution in Selenium? – Devstringx

Back to Blog
Parallel Execution

What is Parallel Execution in Selenium? – Devstringx

In parallel testNG or parallel execution, we can run numerous tests at the same time in different threads so that it can reduce the execution time.

Where test cases are run on numerous browsers or operating systems. Basically, parallel execution helps us to reduce the time and effort of the testing.

It is most commonly used with Selenium, because of the increase in demand for the Cross Browser Testing and we can run Independent test cases only.

With TestNG, we can run test cases in parallel before we have to run test cases sequentially which is time-consuming.

TestNG provides multiple ways for the execution of our tests in separate threads simply by using a parallel attribute in the testng.xml file in the system.

Parallel Tests, Classes, and Methods:

Use parallel attribute on the <suite> tag respectively (for methods,test,classes, instances).

By using parallel attributes we can run methods, tests, and classes in parallel.

The syntax is

<suite name=”My suite” parallel=”methods” thread-count=”5″>

<suite name=”My suite” parallel=”tests” thread-count=”5″>

<suite name=”My suite” parallel=”classes” thread-count=”5″>

<suite name=”My suite” parallel=”instances” thread-count=”5″>

How to Created Parallel Suite?

Below I have created Two test classes and created a parallel suite.

Code-

package testing;import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

public class AmazonTest1 {

WebDriver driver;

@BeforeClass

public void lounchbrowser() {

WebDriverManager.chromedriver().setup();

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get(“https://www.amazon.in/“);

}

@Test

public void test() {

String title= driver.getTitle();

System.out.println(title);

}

@AfterTest

public void testEnd() {

driver.close();

}

}

Recommend to Read:- TestNg Listeners and Types of Listeners in TestNg

package TestNG;import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

public class AmazonTest2 {

WebDriver driver;

@BeforeClass

public void lounchbrowser() {

WebDriverManager.chromedriver().setup();

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get(“https://www.amazon.in/“);

}

@Test

public void test() {

String currentUrl= driver. getCurrentUrl();

System.out.println(currentUrl);

}

@AfterTest

public void testEnd() {

driver.close();

}

}

XML File:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd” ><suite name=”Suite” verbose=”1″ parallel=”classes” thread-count=”2″><test name=”Parallel Test 1″><classes<class name=”AmazonTest1″ />

<class name=”AmazonTest2″ />

</classes>

</test>

</suite>

Share this post

Back to Blog

Hire A Resource