• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / TestNG Tutorial / How to disable Selenium Testcases using TestNG Feature

How to disable Selenium Testcases using TestNG Feature

April 3, 2015 by Mukesh Otwani 5 Comments

Disable Selenium Test

Hello,

Welcome to Selenium Tutorial, Today we are going to discuss very silent feature of TestNG which allow us to enable or disable our test case based on our requirement.

Why to Disable Selenium Test cases?

Before moving forward you should have Eclipse TestNG setup ready if still not configured then please do Selenium Eclipse setup now.

Once our test suite size will increase day by day then chances are high that you don’t want to execute some test cases.

Ok so let’s consider a scenario that you have written 10 testcases but now you want to execute only 5 testcase because other 5 are working correctly

 

How to Disable Selenium Test cases?

In TestNG we can achieve this by simply adding enable attribute and can set value to true/false.

@Test(enable=false)

 

If test case enable as false them while running test cases TestRunner simply will ignore this testcase and will only run testcase whose enable is set to true.

Note- By default @Test is set to enable

Scenario – I have 3 test case but I want to execute only 2 test case.

Precondition- TestNG should be installed

Program for – Disable Selenium Test cases

package demotestcase;

import org.testng.annotations.Test;

public class TestEnableTC {

@Test
public void testLoginApp(){

System.out.println("User is able to login successfully");
}

@Test(enabled=false)
public void testRegisteruser(){

System.out.println("User is able to register successfully");
}

@Test
public void testLogoutApp(){

System.out.println("User is able to logout successfully");
}

}

 

Lets check the output

Disable Selenium Test
Disable Selenium Test

Above program is executing only 2 testcases which has been passed. One test case in not executed  because that test case we have enable =false.

Hope this post helpful for you. Keep sharing with your friends. Comment below if you finding any issue while working with Selenium or TestNG.

Have a nice day 🙂

Like Facebook Page for more updates-Learn-Automation facebook page

Join Selenium Group for discussion and queries- Learn-Automation group

Filed Under: TestNG Tutorial Tagged With: Disable Testcase

Reader Interactions

Comments

  1. Gaurav Khurana says

    January 16, 2017 at 12:17 PM

    That so easy.. Easiest tutorial till date i think. Just a single parameter explained in the best way

    Good for unit testing we can use this when we need to avoid commenting the code
    Thanks

    Reply
  2. sam says

    September 6, 2016 at 12:33 PM

    Hi,

    @Test(enabled=false)
    or
    @Test(enable=false)
    which among them?

    Reply
    • Mukesh Otwani says

      September 6, 2016 at 3:49 PM

      Hi Sam

      @Test(enabled=false) is correct one

      Reply
  3. Mukesh says

    January 28, 2016 at 11:00 PM

    Hi Mukesh,

    I got a case..For suppose i have 100 test cases,in that 100 i want to execute only 20 test cases.Is there any way to skip the 80 test cases,rather using enable=false,for all the 80 test cases.. Please provide the solution.Btw million Thanks for your work man
    .

    Reply
    • Mukesh Otwani says

      March 3, 2016 at 4:32 PM

      Hi Mukesh,

      Grouping of test case will work for you.

      Create group of test cases then decide which group to run which do not has to run via XML file(testng.xml).

      Reply

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?