Note: Below code we will execute using Cucumber Runner class, if you are executing command line your can refer article Cucumber Java Command Line: Ignore or Skip Scenario or Feature
You can ignore Cucumber Tests using tags. not word is used along with tags to ignore the test.
This works both for the Scenario as well as the Feature. You can skip a scenario, set of scenarios, or all scenarios in a feature file. You can also use this in conjunction with AND or OR.
One way of ignoring tags is by mentioning only tags that you want to run in the tags property of CucumberOptions but this is not best practice in a few situations. In that case, we skip tags using not keyword.
Consider below feature file
Feature: Registration, Login and MyAccount Background: Given I am on the home page And I follow "Sign in" @sanity Scenario: Test 1 When I fill "email address textbox" with "firstname.lastname@example.org" Then I fill "password textbox" with "Test1234" @regression Scenario: Test 2 When I fill "registration email textbox" with "email@example.com" Then I click "create an account button" @sanity @regression Scenario: Test 3 When I fill "email address textbox" with "firstname.lastname@example.org" Then I fill "password textbox" with "Test1234" And I click on "Logout" @smoke Scenario: Test 4 When I fill "email address textbox" with "email@example.com"
Examples: Cucumber Skip Ignore Scenarios
Example #1: To execute all scenarios ignoring one tag
To execute all scenarios except @smoke.
tags = ("not @smoke")
Three Scenarios will be executed except the scenario/test #4.
Example #2: Execute Scenario which are tagged with one and not tagged with another
Execute Scenario which are tagged with @regression, not @sanity. This will execute scenario/Test #2.
tags = ("@regression and not @sanity")
Example #3: Execute Scenario which are tagged with one and not tagged with another
Below Code will execute scenario/Test #2 and #3.
tags = ("@regression and not @smoke")
Example #4: Ignore more than one tag
Execute Scenario that are neither tagged with @regression and nor tagged with @sanity. This will only execute scenario/test #4.
tags = ("not @regression and not @sanity")