Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

TestNG Tutorials 30: Groups Attribute at Class Level 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.

Before continuing this post, I will advise you to go through this post first:

@Test annotation at class level in TestNG

Suppose if you need to write multiple @Test annotated methods in a class, and each belongs to same group, you need to mention “groups” attribute for each method which is not easy as you need to write same lines of code again and again. Another problem if you want to update/change group name, you need to go to each test method and change it.

Solution is marking a class to group/s instead of methods.

TestNG allows you to mention “groups” attribute at class level also which will be inherited automatically to @Test annotated methods. It will eliminate writing same lines of code for each methods.

See an example below:

Testng xml:

Output on running:

Overriding “groups” attribute at test method level from class level:

Value of “groups” attribute can be overridden at test level from class level. Calling it “overridden” will not be perfect conceptually because when you declare a group for a test method at test level, that method will actually belong to group mentioned at class level and method level both. It is as good as multiple groups concept in TestNG.

We will see an example below:

Testng xml for group G1:

Output:

All method got executed as all belong to group G1.

Testng xml for group G2:

Output:

Since only method “G1Method3” belong to “G2”, so TestNG executes only that like normal grouping concept.

You can minimise same lines of code and maintenance as well. If you need to change group name, you just need to change at class level instead at each method level.

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: TestNG Tutorials 42: Parameters In TestNG or Parameterization of Methods in a TestNG Class
Next Post: Git Tutorial 32 – How To Restore Deleted And Committed But Not Pushed File Without GIT Reset?

Related Posts

Interview Experience at HP Bangalore for Selenium Profile – Jan– 2020 Uncategorized
Learn Selenium With Quiz – Basic Level 8 – CSS Selector Uncategorized
LeetCode Java Programs Uncategorized
how to install testng plugin in eclipse Uncategorized
Hierarchy of Selenium Classes and Interfaces – Make Selenium Easy Uncategorized
Protractor Tutorial 5 – Introduction & Installation of NodeJS 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