JavaMan
JavaMan

Reputation: 351

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.

Upvotes: 13

Views: 42815

Answers (5)

awgtek
awgtek

Reputation: 1829

This worked for me: not (@FIXME or @IGNORE)

E.g. full command for running maven tests:

mvn -q -B verify "-Dcucumber.options=--tags '@FOO or @BAR' --tags 'not (@FIXME or @IGNORE)' --plugin json:target/reports/report-json/cucumber.json  --plugin html:target/reports/outputhtml.html"

Upvotes: 0

Tiago Mendes
Tiago Mendes

Reputation: 5146

How to exclude/ignore one Tag

(this answer can help other users who just want to ignore one tag)

Terminal:

mvn clean test -Dcucumber.filter.tags="not @one"

Junit:

@CucumberOptions(tags = "not @one")

Upvotes: 3

slowlert
slowlert

Reputation: 21

in general there is the folowing logic behind the tagging:

AND logic is like this:

tags = {"@Tag1", "@Tag2"} //both tags must be present or:
tags = {"~@Tag1", "~@Tag2"} // both tags must not be present, 
//if only one is the stuff will be executed!

OR logic is like this:

tags = {"@Tag1, @Tag2"} //one of these Tags must be present or:
tags = {"~@Tag1, ~@Tag2"} //one of these Tags must not be present, the Rest will be executed!

But i found out, that cucumber soon will support the "or"-Operator in tagging and replace the comma+""-STUFF.., so it is easier to express the differences. It is goind to be like:

tags = {"@Tag1 or @Tag2"}

Original message from system is:

Support for '@tag1,@tag2' will be removed from the next release of Cucumber-JVM. Please use '@tag or @tag2' instead

Hope this can help in future, too. :)

Upvotes: 0

Eswar
Eswar

Reputation: 1055

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.

Upvotes: 14

jmccure
jmccure

Reputation: 1249

Is it possible it doesn't like the Array, maybe try:

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

Upvotes: 1

Related Questions