Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • About Us
  • Toggle search form

TestNG Tutorials 61: Dependency in TestNG – Creating Dependency Among Test Methods – DependsOnGroup

Posted on 02/19/2025 By admin

In previous post, We have learnt to Establish dependency among test methods. In this post, we will see another concept in Dependency called DependsOnGroup.

Consider a scenario:

You have created automation scripts for Integration testing. We know that in integration testing, data flows from one module to another. You divide your test methods as per group. Say Group 1 and group 2. You run Group 1 methods first followed by Methods of Group 2. We can achieve the same in TestNG using DependsOnGroup.

So when we mention a group name or list of group names for a @Test annotated method, all methods of mentioned groups will run first. We will see an example below:

package Dependecy;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class DependsOnGroupsExample {
        
        
        // Test method belong to preSetupTestA
        @Test(groups= {"preSetupTestA"})
        public void methodA()
        {
                System.out.println("MethodA");
        }
        
        
        //Test method belong to preSetupTestA
        @Test(groups= {"preSetupTestA"})
        public void methodB()
        {
                System.out.println("MethodB");
        }
        
        // Test method belong to preSetupTestB
        @Test(groups= {"preSetupTestB"})
        public void methodC()
        {
                System.out.println("MethodC");
        }
        
        // Test method belong to preSetupTestB
        @Test(groups= {"preSetupTestB"})
        public void methodD()
        {
                System.out.println("MethodD");
        }
        
        
        // Test method which is dependent of other groups
        @Test(dependsOnGroups = {"preSetupTestB", "preSetupTestA"})
        public void finalTest()
        {
                System.out.println("Final Test.");
        }
        
        
        
        
}

Output:

[java] [RemoteTestNG] detected TestNG version 6.14.2 MethodA MethodB MethodC MethodD Register on Facebook. PASSED: methodA PASSED: methodB PASSED: methodC PASSED: methodD

PASSED: registerOnFacebook

Uncategorized

Post navigation

Previous Post: Learn Selenium With Quiz – Basic Level 6 – XPath
Next Post: REST Assured Tutorial 68 – Request Logging In Rest Assured

Related Posts

Frequently Asked Java Program 24: Java Program to Capitalize First Character of Each Word in a String Sentence | Make Selenium Easy Uncategorized
Understand Verification & Validation In Software Testing | Make Selenium Easy Uncategorized
November 12, 2017 – Make Selenium Easy Uncategorized
REST Assured Tutorial 41 – Ignore unknown properties during deserialization Using @JsonIgnoreProperties Uncategorized
Understand Defect Life Cycle In Testing Uncategorized
Frequently Asked Java Program 22: Java Program to Trim Whitespace From String Without Using Trim Method Uncategorized

Recent Posts

  • How to Handle iFrames and Nested Frames in Selenium
  • Working with Multiple Windows and Tabs in Selenium WebDriver
  • How to Handle Browser Alerts and Popups in Selenium
  • Thread.Sleep vs Selenium Waits: Why You Should Never Use Thread.Sleep
  • How to Handle NoSuchElementException Gracefully in Selenium

Recent Comments

No comments to show.

Archives

  • September 2026
  • August 2026
  • July 2026
  • June 2026
  • May 2026
  • 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

  • Advanced Interactions
  • Getting Started
  • Locators and Elements
  • Uncategorized
  • Waits and Synchronization

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark