TestNG Tutorials 32: Customizing TestNG xml For Methods Belong to Multiple Group Names

Hello Folks,

In last post, we learnt about Multiple groups names foe test and configuration methods.

When we assign a method to multiple groups, you find difficulties when you want to run methods belong to only particular groups or to only some groups.

For example: Suppose There are three methods M1 ( belongs to G1), M2(Belongs to G1 and G2) and M3(G1, G2 and G3). If you want to run methods which only belongs to G1 ( not G2 or G3), you will find it difficult to call in testng xml.

We will see an example below:

Scenario 1:

Now I want TestNG to run methods which belongs to only group G1 i.e. MethodsBelongToG1 . If we create testng xml as below:

Output:

Here we did not expect above result. We wanted only “MethodsBelongToG1” to run but it ran all methods which belong to G1.

How to achieve that now?

You just need to exclude remaining groups in testng xml as below:

Output:

Now we got desired output.

Scenario 2:

If you want to run methods which belong to either only G1 or G2, you need to add groups in testng xml as below:

Output:

But above approach will not work if you want to run methods which belong to G1 and G2 together i.e. not only to G1 or G2. We have a solution for that which we will see in next posts.

More about TestNG in upcoming posts. Stay tuned.

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

Leave a Reply

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