Parallel Testing using Selenium WebDriver with TestNG Framework

Back-End Dev Note September 20, 2022

Hello, I’m Carlo Jay Mojica, a Software QA Engineer for almost 3 years now here in Commude PH. I’ve been testing projects manually for about 2 years. Now, I want to expand my QA skills and learn Automation testing. There are a lot of Automation tools that I want to learn, but now I’m focusing on Selenium WebDriver using TestNG Framework.

 

Selenium WebDriver is an open-source tool that automates browsers. I’m still studying this automation tool, and I’m not yet that confident to apply automation testing to the projects I’m handling. Once I finish learning Selenium, I’ll perform it on my assigned projects right away. Thank you Commude PH for approving my Udemy Course request. Arigatō Gozaimasu!

 

In this article, I’ll show you how to perform Parallel Testing in Selenium WebDriver with TestNG Framework. Meaning, you can run tests on either Firefox & Chrome, Chrome & Edge, Firefox & Edge, and vice versa at the same time.

 

I will use a test demo site https://demoqa.com/ for the Parallel testing on Chrome & Firefox browsers. What I will do is :

 

 

            1. Go to https://demoqa.com/ site

            2. Go to Forms Page

            3. Click Elements dropdown

            4. Select and click Text Box button

            5. Fill up all the forms

            6. Click Submit button

 

 

Let’s get started. 

  • The first thing to do is to open Eclipse IDE ⇾ Create Java Project ⇾ Create Package ⇾ Create TestNG Class.
  • In the class that I’ve created, I will use @BeforeClass, @Test, & @AfterClass Annotations.
    • In @BeforeClass, I’ve created the setUp() method that contains the setting up of the browser drivers (Firefox & Chrome), maximizing the browser, etc. Basically setting up the browser before methods under @Test Annotation run. 

 

@BeforeClass (Setting up the browser)

 

 

  • After setting up the browser, it will now proceed to run methods under @Test Annotation. I’ve created the fillUpTextBox method that contains the testing part of the code.

 

 

@Test (Filling up the text box form)

 

 

  • Then lastly, @AfterClass Annotation, I’ve created a cleanUp() method that simply has a waiting time then the browser will close.

 

 

@AfterClass (Waiting time before closing the browser)

 

  • After I finish coding the Test_Parallel TestNG class, it’s not yet ready to run automation. I need to create an XML file. I will name it “demoqa-test-parallel.xml”.

 

 

.xml file required for running TestNG class

 

 

 

  • You will see that Firefox and Chrome browsers open and run the same test script successfully.

 

 

TestNG running suite log / console

 

TestRig Technologies states, “Parallel testing enables teams to focus on making tests repeatable, measurable, and accurate. By simply testing faster, you can test more, and testing more produces more actionable data to find bugs and also improve test cases.”

 

And that’s how Parallel Testing in Selenium WebDriver with TestNG FrameWORKS!!! *Wink* *wink*. If you have any questions regarding this article, you can contact me at carlo_mojica@commude.ph.