Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

SELENIUM INTERVIEW QUESTION 6 – All Ways to Exclude/Ignore/Disable a Test Method in TestNG

Posted on 03/16/2025 By admin

Refer all Selenium interview question here.

Learn and share to reach it maximum.

When we integrate Selenium with TestNG, we create test methods using @Test annotation provided by TestNG. You can create test methods as many as you want. But sometimes you may need to ignore or disable test to exclude it while running as a suite , method or class level. We will see all ways to ignore a test method in this post.

We have three ways to ignore a test method:-

  1. Using @Ignore annotation of TestNG
  2. By setting “enabled” attribute as false for @Test annotated method
  3. By using “exclude” tag in testng xml

Let’s see every option in details.

This is this latest feature provided by TestNG. I have already covered about it here. So I will not repeat it again here.

Ignore Annotation in TestNG

Difference between @Ignore and enabled attribute in TestNG

Ask me in comments if you have any doubt.

This is traditional way and can be used if you are using older version of TestNG. “enabled” is an attribute of @Test annotation. Default value is always true to include it in run. You can set it false to exclude a particular test from running.

package TestNGEx;

import org.testng.annotations.Test;

public class EnabledAttribute {
        
        @Test
        public void Method1()
        {
                System.out.println("Will be running");
        }
        
        @Test(enabled=false)
        public void Method2()
        {
                System.out.println("Ignored using enabled as false");
        }

}

Output:-

Above two ways are good if you are doing at individual method or class level. But when you are running in a suite, it will be really difficult to manage at individual level. You may need to keep enabling or disabling tests. In that case you can use testng xml to manage it externally rather than modifying on method or class level. You can achieve easy scalability and modification if use enabling disabling test using testng xml.

Testng xml:-



           

Output:-

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

Uncategorized

Post navigation

Previous Post: How To Launch Microsoft Edge Browser In Selenium WebDriver – Java
Next Post: access token

Related Posts

Java Programs | Make Selenium Easy Uncategorized
AfterBefore – Make Selenium Easy Uncategorized
July 16, 2019 – Make Selenium Easy Uncategorized
ransom notes Uncategorized
scrollBy500 – Make Selenium Easy Uncategorized
TestNG Tutorials 55: DataProvider in TestNG – Lazy Initialisation of DataProvider Method – Use of Iterator Return Type | Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • 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

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark