How to disable Selenium Test Cases using TestNG Feature

HOME

In the previous tutorial, we have discussed about prioritizing the Test Cases using TestNG. In this tutorial, we will see how we can disable the Test Cases using TestNG. 

Imagine there are 100 test cases in Regression Test Suite. We need to execute 99 test cases in a release  and want not to execute any particular test case. But we do not want to delete that test case from the Test Suite also. In this case, TestNG has a feature which allows to skip a particular test case by setting the parameters to

@Test(enabled = false)

To use two or more parameters in a single annotation, separate them with a comma:

@Test(priority = 3, enabled = false)

To Run the TestNG program, right click on the program,  select Run As TestNG Test

Below is an example to implement the above mentioned scenario

import org.testng.annotations.Test;
 
public class TestNGDisableDemo {
 
    @Test(priority = 3)
     public static void FirstTest() {
           System.out.println("This is Test Case 1, but after priority Test Case 3");
     }
 
     @Test(priority = 4)
     public static void SecondTest() {
          System.out.println("This is Test Case 2, but after priority Test Case 4");
     }
 
     @Test(enabled = false)
     public static void ThirdTest() {
           System.out.println("This is Test Case 3, but now skipped");
     }
 
     @Test(priority = 1)
     public static void FourthTest() {
            System.out.println("This is Test Case 4, but after priority Test Case 1");
     }
}

Output 
This is Test Case 4, but after priority Test Case 1
This is Test Case 1, but after priority Test Case 3
This is Test Case 2, but after priority Test Case 4
PASSED: FourthTest
PASSED: FirstTest
PASSED: SecondTest
===============================================
    Default test
    Tests run: 3, Failures: 0, Skips: 0
===============================================
   
===============================================
Default suite
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0
===============================================

2 thoughts on “How to disable Selenium Test Cases using TestNG Feature

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s