Cucumber Skip Test Command Line

Profile picture for user devraj

In several situation you might want to ignore some of scenarios, consider you are maintaining same feature file for automation and manual scenarios and you want to tag manual scenarios with @manual or @ignore and  you don't want to execute them along with other test cases.

In our previous tutorial, we have discussed how we can do it using Cucumber Runner class, in this we will achieve the same goal using terminal or command line. I hope you already configured Cucumber Command Line using Maven on your system, in case it's not configured you can watch previous video.

So, for demo we will consider this feature file:

Feature: Registration, Login and MyAccount
 
  Background: 
 	  Given I am on the home page
    And I follow "Sign in"	  
 	   
  @smoke
  Scenario: Verify Login Functionality
    When I fill "email address textbox" with "goswami.tarun77@gmail.com"
    Then I fill "password textbox" with "Test1234"  
   
 @regression
  Scenario: Create New User
    When I fill "registration email textbox" with "goswami.tarun77+1@gmail.com"
    Then I click "create an account button"
    
  @sanity @regression
  Scenario: Verify Logout Functionality
    When I fill "email address textbox" with "goswami.tarun77@gmail.com"
    Then I fill "password textbox" with "Test1234"
    And I click on "Logout"      
    
 @manual
  Scenario: Verify Ignore Test Case
    When I fill "email address textbox" with "goswami.tarun77@gmail.com"

Here you can see we have 4 scenarios tagged with @smoke, @regression, @sanity+@regression and @manual. 3rd scenario is having 2 tags @sanity and @regression.

Now Let's see different ways of ignoring scenarios:

Example #1: Execute only @smoke scenario

$ mvn test -Dcucumber.filter.tags="@smoke"

It will execute only one scenario which is tagged with @smoke and ignore all other scenarios.

Example #2: Skip or Ignore scenarios which are tagged with @manual

$ mvn test -Dcucumber.filter.tags="not @manual"

This will execute 3 scenarios out of 4, all 3, except the @manual one.

Example #3: Ignore or Skip multiple tags

$ mvn test -Dcucumber.filter.tags="not @manual and not @sanity"

This will execute 2 test scenarios excluding @manual and @sanity. Can you try by yourself by replacing @sanity with @regression that how many scenarios executed?

Example #4: Execute @regression tag ignoring @sanity

$ mvn test -Dcucumber.filter.tags="@regression and not @sanity"

This will execute 2nd test scenario, 3rd scenario will be ignored, since it has @sanity tag. These are some example, in real world you might have to use different combination as well.