Can Selenium use multi threading in one browser?

Selenium can use multi−threading in one browser with the help of TestNG framework. TestNG provides the feature of parallel execution which works on the concept of Java multi−threading.

To execute tests based on various parameters, the TestNG has an XML file where we have the configurations. The attributes parallel and thread−count are used for parallel execution.

The parallel attributes can have the following values −

  • Classes − to execute all tests in a class within a one thread.

  • Instances − to execute all methods in the same instance within one thread.

  • Tests − to execute all methods in the same tag within one thread.

  • Methods − to execute methods in different threads.

The thread−count attribute determines the count of threads that we want to have while executing tests.


import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
public class TestNG14 {
   public void testCase1() {
      System.out.println("This is the first Test Case");
   public void testCase2() {
      System.out.println("This is the second Test Case");
   public void testCase3() {
      System.out.println("This is the third Test Case");
   //executed after all methods in the same class
   public void afterClass() {
      System.out.println("This will execute after the Class");


Code Implementation of xml file.

<!DOCTYPE suite SYSTEM "−1.0.dtd" >
<!−−parallel set to methods with thread count 2−−>
<suite name="Test−Suite" parallel="methods" thread−count="2">
   <test name="Tutorialspoint Test" >
         <class name="TestNG14" />


TestNG results in a format of report.