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.

First Test Scenario and its Requirements

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

Test Design:

1) 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.

2) DesiredCapabilities Manager Class:

This class has a “getDesiredCapabilities” method and it takes browser name and platform as a parameter then it constructs capabilities as per specific browser types.

3) TestBase Class:

In Base Test class, I will instantiate Thread Local Driver Factory and Desired Capabilities Manager classes and handle @BeforeTest and @AfterTest implementations. @BeforeTest gets browser and platform parameters from TestNG.xml file (I will describe it soon),  I will create capabilities, and get driver by using methods of DesiredCapsManager and TLDriverFactory classes. @AfterTest, I closed open drivers.

4) FirstTest Class:

5) SecondTest Class:

6) TestNG.xml File:

7) POM.xml:

Github Link: https://github.com/swtestacademy/TestNGParallel/tree/NewParallelTestNGImplementation

I also wrote other parallel test execution code. You can find that code on below page.

Github Link: https://github.com/swtestacademy/TestNGParallel/tree/TestNGParallel3

Thanks.
-Onur