Make Selenium Easy

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

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.