What are the different ways of running tests parallel in selenium with testng

There are several ways to run Selenium tests in parallel using TestNG. TestNG allows you to execute methods, classes, or test tags concurrently by configuring the parallel attribute in the TestNG suite file.

Below is an example testng.xml suite file that demonstrates how to execute test classes in parallel:

testng.xml

<suite name=”ParallelSuite” parallel=”methods” thread-count=”2″>

<test name=”ParallelTests”>

<classes>

<class name=”TestClass” />

</classes>

</test>

</suite>

By setting the parallel attribute in the TestNG suite file, we can control how tests are executed in parallel:

  • Setting parallel="methods" runs test methods in parallel within the same class.
  • Setting parallel="tests" allows multiple <test> blocks to run simultaneously.
  • Setting parallel="classes" enables parallel execution of different test classes.

Below is an example TestClass demonstrating parallel method execution:

import org.testng.annotations.Test;

public class TestClass {
@Test
public void test1() {
System.out.println(“Test 1 – ” + Thread.currentThread().getId());
}

@Test
public void test2() {
    System.out.println("Test 2 - " + Thread.currentThread().getId());
}

}

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox , Smart Fitness Guide , CodesToolbox , Testing Forum
Scroll to Top
0
Would love your thoughts, please comment.x
()
x