javascalacucumbercucumber-junit

How to exclude cucumber tags


I have a bunch of IT cases with various cucumber tags. In my main runner class I want to exclude all the scenarios which have either @one or @two. So, below are the options I tried Option 1

@CucumberOptions(tags=Array("~@one,~@two"), .....)

or option 2

@CucumberOptions(tags=Array("~@one","~@two").....

When I tried with option one, test cases tagged with @two started executing while with second option it did not. As per cucumber documentation an OR will be maintained when tags are mentioned as "@One,@Two". If this is the case why doesn't exclude work the same way i.e. the first option?

Update: This piece of code is written in scala.


Solution

  • I think I figured out how it works.

    @Cucumber.Options(tags = {"~@one, ~@two"}) - This translates to if '@one is not there' OR if '@two is not there' then execute the scenario

    So all the scenarios in the below feature are executed. Because, the first scenario has tag @one but not @two. Similarly Second scenario has tag @two but not @one. Third Scenario has neither @one nor @two

    Feature:
      @one
      Scenario: Tagged one
        Given this is the first step
    
      @two
      Scenario: Tagged two
        Given this is the first step
    
      @three
      Scenario: Tagged three
        Given this is the first step
    

    To test my understanding, I updated the feature file as below. With this change, all scenarios without tags @one or @two were executed. i.e @one @three, @two @three and @three.

    Feature:
      @one @two
      Scenario: Tagged one
        Given this is the first step
    
      @two @one
      Scenario: Tagged two and one
        Given this is the first step
    
      @one @three
      Scenario: Tagged one and three
        Given this is the first step
    
      @two @three
      Scenario: Tagged two and three
        Given this is the first step
    
      @one @two @three
      Scenario: Tagged one two and three
        Given this is the first step
    
      @three
      Scenario: Tagged three
        Given this is the first step
    

    Now if we do an AND operation: @Cucumber.Options(tags = {"~@one", "~@two"})- this means execute a scenario only when BOTH @one and @two are not there. Even if one of the tag is there then it will not be executed. So as expected, only scenario with @three got executed.