In this article, I will describe how to do parallel testing on your PC (local computer) without using Selenium Grid. There are several techniques to do this operation and I will share with you some code samples.

In my former articles, I described parallel testing theory so in this tutorial I do not want to go into details. I will give the test scenarios and their implementations. Also, I will describe the details of each test files and I will add informative comments in my test automation codes.

Test Scenario for Parallel Testing

  • We will have two test classes.
  • First Class has three methods and all methods must open Google and check its title. First class’s test methods must run on Firefox.
  • Second Class has two methods and first test method must open Google and checks its title, second test method opens Yandex and checks its title. Second class’s test methods must run on Chrome.
  • All tests have to Run in Parallel in Locally!

Test Design:

1) OptionsManager Class:

This class has a “getChromeOptions” and “getFifefoxOptions” methods and they take browser name as a parameter then they provide related options as per specific browser types.

2) ThreadLocal Driver Factory Class:

First of all, for Thread-Safe test automation, I will use ThreadLocal<WebDriver> and I will create a ThreadLocalDriverFactory (TLDriverFactory) class to set ThreadLocal driver and get Webdriver.

3) TestBase Class:

In Base Test class,  @BeforeMethod I got browser parameter from TestNG.xml file (I will describe it soon),  and I set and get ThreadLocal Driver by using TLDriverFactory class. @AfterMethod, I closed the driver.

4) FirstTest Class:

5) SecondTest Class:

6) TestNG.xml File:

7) POM.xml:

Click here to go to Github Link


If you have several test classes and in those test classes if you have more than one test methods, then you can run those test classes and methods in parallel with below TestNG configuration.

Above configuration runs two parallel test classes because of below line.

<suite thread-count=”2″ name=”Suite” parallel=”tests” >

And it also runs five test methods of test class one in parallel too by using below line.

<test name=”com.FirstTest” parallel=”methods” thread-count=”5″>

And it also runs four test methods of test class two in parallel too by using below line.

<test name=”com.SecondTest” parallel=”methods” thread-count=”4″>

Here is the result for parallel testing in local machine!

Execution Order of Parallel Testing in Local Computer:

Google2 Test Started! 15
Google1 Test Started! 13
Google0 Test Started! 14
Google1 Test’s Page title is: Google 13
Google1 Test Ended! 13
Google2 Test’s Page title is: Google 15
Google0 Test’s Page title is: Google 14
Google2 Test Ended! 15
Google0 Test Ended! 14

Selenium Webdriver Tutorial Series