Concept of TestNG Groups

Last updated on Nov 28 2021
Vidhya Prakesh

Table of Contents

Concept of TestNG Groups

TestNG Groups allow you to perform groupings of varied test methods. Grouping of test methods is required once you would like to access the test methods of varied classes.
Not only you’ll declare the methods within a specified group, you’ll also declare another group within a specified group. Thus, TestNG are often asked to include a specific set of groups while excluding another set of groups.

It provides you maximum flexibility by partitioning your test methods in groups and doesn’t require recompilation of test cases if you run your two different sets of test cases back to back.
Groups are laid call at the testng.xml file with tag. Groups are often specified either within the tag or tag. If the tag is specified inside the tag, then it’s applied to all or any or any the tags of XML file. If the tag is specified within a selected folder, then it’s applied thereto particular tag only.
Let’s understand the concept of TestNG Groups through an example:
Test cases within Groups
First case: When tag is defined inside the tag.

Step 1: Open the Eclipse.

Step 2: We create three java projects

i.e.  Personal_loan.java, Home_loan.java, and Car_loan.java.

Personal_loan.java

package com.tecklearn;
import org.testng.annotations.Test;
public class Personal_loan
{
@Test(groups= {"SmokeTest"})
public void WebLoginPersonalLoan()
{
System.out.println("Web Login Personal Loan");
}

@Test
public void MobileLoginPersonalLoan()
{
System.out.println("Mobile Login Personal Loan");
}
@Test
public void APILoginPersonalLoan()
{
System.out.println("API Login Personal Loan");
}
}

Home_loan.java

package com.tecklearn;
import org.testng.annotations.Test;
public class Home_loan{
@Test
public void WebLoginHomeLoan()
{
System.out.println("Web Login Home Loan");
}
@Test(groups= {"SmokeTest"})
public void MobileLoginHomeLoan()
{
System.out.println("Mobile Login Home Loan");
}
@Test
public void APILoginHomeLoan()
{
System.out.println("API Login Home Loan");
}
}

Car_loan.java

package com.tecklearn;
import org.testng.annotations.Test;
public class Car_loan
{
@Test
public void WebLoginCarLoan()
{
System.out.println("Web Login Home Loan");
}
@Test
public void MobileLoginCarLoan()
{
System.out.println("Mobile Login Home Loan");
}
@Test(groups= {"SmokeTest"})
public void APILoginCarLoan()
{
System.out.println("API Login Home Loan");
}
}

In the above case, we provide a gaggle name

i.e. SmokeTest to three test cases of three different classes.

Step 3: Now, we create a testng.xml file where we configure the classes that we’ve created and add new tag . we might wish to execute those test cases which have a gaggle “SmokeTest“.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- Test -->
<!-- Test -->
<!-- Test -->
<!-- Suite -->

Output

testng.xml

Second case: When tag is defined inside the tag.

The testng.xml would look like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- Test -->
<!-- Suite -->

Tests belonging to multiple Groups

Step 1: Open the Eclipse.

Step 2: We create a java project named as “Groups.java“.

Groups.java

package com.tecklearn;
import org.testng.annotations.Test;
public class Groups {
@Test(groups= {"Group A"})
public void testcase1()
{
System.out.println("Test case belonging to Group A");
}
@Test(groups= {"Group A","Group B"})
public void testcase2()
{
System.out.println("Test case belonging to both A and Group B");
}
@Test(groups= {"Group B"})
public void testcase3()
{
System.out.println("Test case belonging to Group B");
}
}

In the above code, we define two groups, i.e., A and B . The testcase1() is tagged with a ‘Group A‘, testcase2 is tagged with two groups ‘Group A‘ and ‘Group B‘, and testcase3() is tagged with a ‘Group B‘.

Step 3: We create the testng.xml file to configure the Groups class.

testng.xml 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- Test -->
<!-- Test -->
<!-- Suite -->

Step 4: Run the testng.xml file by clicking right click on the testng.xml file.

Output  

2 62

 

Including/Excluding Groups

Step 1: Open the Eclipse.

Step 2: We create a replacement java project.

Groups.java

package com.tecklearn;
import org.testng.annotations.Test;
public class Groups
{
@Test(groups= {"Include Group"})
public void test_case1()
{
System.out.println("This is test case 1");
}
@Test(groups= {"Include Group"})
public void test_case2()
{
System.out.println("This is test case 2");
}
@Test(groups= {"Exclude Group"})
public void test_case3()
{
System.out.println("This is test case 3");
}
}

Step 3: we’ll create the testng.xml file.
testng.xml 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- Test -->
<!-- Suite -->

Step 4: Run the testng.xml file.

Output

3 62

Using Regular Expressions

We can also use regular expressions with TestNG Groups.

Let’s understand through an example:

Step 1: Open the Eclipse.

Step 2: We create a java project named as “Regular_Expression.java”.

Regular_Expression.java

package com.tecklearn;
import org.testng.annotations.Test;
public class Regular_Expression {
@Test(groups= {"Include test case1"})
public void test_case1()
{
System.out.println("This is test case 1");
}
@Test(groups= {"Include test case2"})
public void test_case2()
{
System.out.println("This is test case 2");
}
@Test(groups= {"Exclude test case3"})
public void test_case3()
{
System.out.println("This is test case 3");
}
}

Step 3: Now we create the testng.xml file to configure the above class.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- Test -->
<!-- Suite -->

Step 4: Run the testng.xml file.

Output

4 58

 

Groups in Groups

 

We can also specify a gaggle within another group. The groups which are defined in another groups are mentioned as Meta Groups.

Let’s understand through an example:

Step 1: Open the Eclipse.

Step 2: We create a java project named as “Groups_in_Groups“.

Groups_in_Groups.java

package com.tecklearn;
import org.testng.annotations.Test;
public class Groups_in_Groups
{
@Test(groups= {"Smoke"})
public void test1()
{
System.out.println("test1");
}
@Test(groups= {"Regression"})
public void test2()
{
System.out.println("test2");
}
@Test
public void test3()
{
System.out.println("test3");
}}
Step 3: Now we create a testng.xml file where we configure the above class.
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- Test -->
<!-- Suite -->

In the above xml file, we define a replacement group within another group named as “Group 1” which we’ve include those test cases which are tagged with “Smoke” and “Regression”.

Step 4: Run the testng.xml file.

Output

5 53

 

So, this brings us to the end of blog. This Tecklearn ‘Concept of TestNG Groups’ blog helps you with commonly asked questions if you are looking out for a job in Selenium and Automation Testing. If you wish to learn Selenium and build a career in Automation Testing domain, then check out our interactive, Selenium Certification Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/selenium-training-certification/

Selenium Certification Training

About the Course

Tecklearn’s Selenium Certification Training enables you to master the complete Selenium suite. The Selenium Training is designed to train developers and manual testers to learn how to automate web applications with a robust framework, and integrate it within the DevOps processes of an organization. This Selenium Certification Training will also help you master important concepts such as TestNG, Selenium IDE, Selenium Grid, Selenium WebDriver, etc. Get hands-on experience on widely used automation frameworks such as Data-Driven Framework, Keyword-Driven Framework, Hybrid Framework, and Behavior Driven Development (BDD) Framework. Throughout this online Instructor-led Selenium Certification Training, you will be working on real-life industry use cases.

Why Should you take Selenium Certification Training?

• The average salary of a Selenium Test Automation Engineer is $94k per year – Indeed.com.
• Automation Testing Market is expected to grow at a Compound Annual Growth Rate (CAGR) of 18.0% in the next three years.
• Global software testing market to reach $50 billion by 2020 – NASSCOM. Selenium tool supports more browsers and languages than any other testing tool.

What you will Learn in this Course?

Getting started with Selenium

• Introduction to Selenium testing
• Significance of automation testing
• Comparison of Manual and Automation Testing
• Installation of Java JDK, JRE and Eclipse

Setting the environment in Eclipse for Selenium

• Java Introduction
• Creating a Java function and executing
• Concepts of Java
• Properties File
• Reading Data from Excel File
• Database Connection
• Hands On

Advantages of Selenium automation testing

• Selenium Features
• Concept of Selenium Integrated Development Environment
• Understanding of the Selenium IDE features
• Addition of Script assertions and general commands
• Deploying the first Selenium Script
• Sample project IDE
• Recording Selenium test case
• Hands On

Selenium Web driver Automation

• Architecture of Selenium Web Driver
• Download and installation
• Creating a Java function using Selenium and execution
• Hands On

Deploying Web Drivers for scripting

• Getting the HTML source of Web Element
• Table and Form Elements
• Firebug extension and Fire Path installation
• Advance User Interactions and Cross Browser Testing
• Hands On

Deep dive into Selenium Web Driver

• Action Commands
• Web Table / Date Picker
• How to Implement Switching Commands in WebDriver
• Alerts
• Frames
• Hands On

Switching Operations in WebDriver using Window

• Selenium Webdriver Wait
• Implicit wait, Explicit wait
• Deploying searching elements using the link text, name, using XPath
• Calendar
• Hands On

Introduction to TestNG Framework

• Introduction to TestNG
• Advantages of TestNG
• Installing TestNG on Eclipse
• Rules to write TestNG
• TestNG Features
• Annotations
• Grouping
• Sequencing: Prioritization and Dependency
• Enable/Disable a test case
• Parameterization: Using Xml file and DataProvider
• Parallel Testing & Cross Browser Testing
• TestNG Report: HTML Report, Console Report, XML Report

JUnit Operations and Test Framework

• Annotations, Methods in JUnit
• Junit Test Suites, ANT Build and JUNIT reporting
• Types of Test Automation Framework
• Module Based Testing Framework
• Data Driven Testing Framework
• Keyword Driven Testing Framework
• Hybrid Driven Testing Framework
• How to implement Testing Framework in Project
Object Repository
• Understanding of Object Repository
• Learning sample scripts using object repository
• Page Object Modelling
• Page Factory
JavaScript Functions
• Autosuggestion
• Headless Browser
• Sikuli
• XPath

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "Concept of TestNG Groups"

Leave a Message

Your email address will not be published. Required fields are marked *