TestNG Tutorials 63: Dependency in TestNG – Usage of Regular Expressions with DependsOnGroup

Hello Folks,

We have learnt in previous posts regarding establishing relationship between test methods. You can go through them below:

Dependency in TestNG – Creating Dependency Among Test Methods – DependsOnMethod

Dependency in TestNG – Creating Dependency Among Test Methods – DependsOnGroup

In this post, we will learn how can we use regular expressions with DependsOnGroup.

Regular expression helps you in defining a pattern for similar items. If your test is dependent on multiple groups of tests, either you can pass each group name in dependsOnGroups array or pass  regular expressions if group names follows a pattern. We will see examples below:

 

Output:

[RemoteTestNG] detected TestNG version 6.14.2
Signed Up
Registration Was successful
Logged In
Log In was successful.
purchased Something
PASSED: signUp
PASSED: verifyRegistration
PASSED: logIn
PASSED: verifyLogIn
PASSED: purchaseSomething

===============================================
    Default test
    Tests run: 5, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 5, Failures: 0, Skips: 0
===============================================


Above way will be complex if you more number of groups or adding or deleting a new group. Every time you may need to edit group names in dependsOnGroups array. But if you name group in some pattern, you can use regular expressions as shown below:

Output:

[RemoteTestNG] detected TestNG version 6.14.2
Signed Up
Registration Was successful
Logged In
Log In was successful.
purchased Something
PASSED: signUp
PASSED: verifyRegistration
PASSED: logIn
PASSED: verifyLogIn
PASSED: purchaseSomething

===============================================
    Default test
    Tests run: 5, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 5, Failures: 0, Skips: 0
===============================================


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

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning