Best and easy way to Group test cases in selenium

I am sure you must have got this question in mind that is there any way to group a set of test cases in Selenium,yes we have TestNG group feature which will allow you to Group test cases in selenium webdriver.

Grouping in Automation is quite interesting feature through which you can easily categorize your test cases based on requirement.

For Example- If we  have 200 test case out of these some are end to end test cases, some are the functional test case and some are regression or smoke test cases so if you don’t categorize these test cases these all test case will come under one common category.

Group test cases in selenium

Group test cases in selenium



Group Selenium Script using TestNG

For grouping in Selenium, we have to use TestNG feature through which we can create groups and maintain them easily.

We can include and exclude groups through testng.xml file


 How to create group in TestNG

We have predefined syntax for this




We can create multiple groups as well


After grouping in Selenium we can specify the include and exclude in testng.xml.

<include> – It tells testng.xml that which group we need to execute.

<exclude>- It tells testng.xml which group we have to Skip


Therefore, if you execute your test cases with grouping then we have to modify our testng.xml file and we have to explicitly specify the group.

Complete program to group test cases in selenium


We need to modify the  testng.xml to Group test cases in selenium


I created a new tag called group, inside group we have mention include and exclude tag, and we have mention group name, which we have to include and exclude.


Once you run above XML it will run all the test cases, which belongs to Smoke group category.

Let us run this xml and see the output.


Group test cases in selenium


 Console output.


Group Selenium Script using TestNG

Check out HTML Reports as well after executing scripts. You can verify included and excluded the group in report itself.

Visting XSLT reports also for attractive reports.


Thanks for visiting my blog. Share this post with others as well.

Comment below if finding any issue. Have a nice day 🙂



  1. Anindita
      • Anindita
  2. Prashant
  3. Lalit Aggarwal
    • Mukesh Otwani
      • Lalit Aggarwal
  4. Puneeth
    • Mukesh Otwani