Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

TestNG Tutorials 29: Grouping Configuration Methods in TestNG

Posted on 02/19/2025 By admin

Hello Folks,

In previous post, we learnt about basics of group concepts in TestNG and how to use with @Test annotated methods. In this method we will see how can we use grouping concept with configuration methods.

Below are the configuration methods provided by TestNG:

@BeforeSuite @AfterSuite @BeforeTest @AfterTest @BeforeGroups @AfterGroups @BeforeClass @AfterClass @BeforeMethod

@AfterMethod

These configuration methods may be different for each test scripts or/ and common for some test scripts. Suppose, to run “Test Case 1” and “Test Case 2” you need “Test Configuration 1” while for “Test Case 3” and “Test Case 4” you need “Test Configuration 2”.

To achieve this, you have two solutions:

  1. Create a separate base configuration class for test scripts and extend.
  2. Group configuration methods

Create a separate base configuration class for test scripts:

Test Configuration 1 for “Test Case 1” and “Test Case 2”:

Test Case 1:

Testscript1.xml (Testng xml):

Output:

In the same way, you need to create “Test Configuration 2” for “Test Case 3” and “Test Case 4”. You need to create multiple class files if you have so many different configurations.

Grouping configuration methods:

You can group configuration methods ( like we do @Test annotated method) as well and handle group to be included or excluded through testng xml. Let’s understand this through an example:

Configuration methods class:

Test methods:

To run G1 scripts, testng xml is as below:

Output:

To run G2 scripts, testng xml is as below:

Output:

Both approaches are good. Both have their own advantages. Whatever you feel simple to understand and implement you can use.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below. If you like my posts, please like, comment, share and subscribe. #ThanksForReading

#HappySelenium

Uncategorized

Post navigation

Previous Post: Selenium
Next Post: Introduction To Apache POI – The Java API To Read Write Microsoft Documents – Excel

Related Posts

May 5, 2018 – Make Selenium Easy Uncategorized
Interview Experience at HP Bangalore for Selenium Profile – Jan– 2020 Uncategorized
SkipExceptionFailed – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
April 1, 2018 – Make Selenium Easy Uncategorized
Manual Testing | Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark