How to exclude cucumber tags
Asked Answered
C

4

13

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.

Ceremonial answered 9/2, 2015 at 11:42 Comment(0)
B
14

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.

Boondoggle answered 9/2, 2015 at 20:37 Comment(2)
I tried with similar examples on my machine and was able verify this behavior.Ceremonial
Also if you want to do and and from the cucumber command line runner you have to say something like: --tags @a --tags @b. For or it would be like --tags @a,@bBaudekin
H
2

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")
Holtz answered 28/4, 2021 at 17:42 Comment(0)
K
1

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

@CucumberOptions(tags={"~@one,~@two"}, .....)
Kakaaba answered 9/2, 2015 at 19:33 Comment(1)
My apologies that I did not mention that the code I have in the question is in ScalaCeremonial
D
0

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. :)

Daisey answered 29/4, 2020 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.