'Using tags to exclude group of features [duplicate]
We are using tags to be able to group features and senarios. For example, we have something like:
@jira=123
Scenario: test scenario 1
...
@jira=456
Scenario: test scenario 2, known failure
...
Scenario: test scenario 3, new feature
Now, we are hoping to run test that are not tagged with @jira=123 or @jira=456. Because we have many features and scenarios tagged with the @jira=somevalue, it is impractical to add them all. So I am looking for a way to be able to exclude anything tagged with @jira. I tried ~@jira and "~@jira=" but no luck. Looking at the following junit case:
Which is using "@foo=" as a tag, but was not able to find an example. Is there a way to exclude a group of scenarios tagged by @jira, regardless of the tag value ?
Solution 1:[1]
Yes, we haven't documented this well but this question here can be a start. Karate actually supports a mini expression language for tags.
Have a look at this test for some options: TagsTest.java
And this should work for your requirement, do confirm in the comments ! Yes just use the string below where you would normally put @jira
etc.
!valuesFor('@jira').isPresent
One more important point. When you use the special expression language, any AND or OR complexity has to be managed within the single expression that you pass into the tags
option. Only one expression is needed and the use of comma-separated values or multiple values for the tag
parameter is not applicable.
For example:
To select scenarios that have values for either the @fail
tag or the @bad
tag (note the use of the JS ||
(OR) operator):
valuesFor('@fail').isPresent || valuesFor('@bad').isPresent
And to select any scenario that has values for the @fail
tag and where the @smoke
tag is present (without values, just the plain tag and no =
part):
valuesFor('@fail').isPresent && anyOf('@smoke')
And yes, you can use the "expression language" on the command-line i.e. within the karate.options
or as the --tags
or -t
option to the stand-alone JAR: https://stackoverflow.com/a/72054253/143475
Solution 2:[2]
The tag value is the whole string, even if it contains a =
and you may assume there is key and a value.
But you could consider to use multiple tags, they are allowed.
So, in your case, I would use something like:
@jira=123
@jira
Scenario: test scenario 1
...
@jira=456
@jira
Scenario: test scenario 2, known failure
And the you can use the ~@jira
to exclude all the @jira
scenarios.
This will allow you to still reference the single @jira=123
when needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | aleruz |