TUTORIAL 3 :Using Tags in Cucumber

Table of contents
Reading Time: 2 minutes

Hello Everyone, Now We will go through the TAGS in cucumber. You can read the previous post related to how to write a  Test Script in CUCUMBER : here

In chapter of Feature if we have many Scenarios , to put them under a single umbrella, we use tags in our cucumber through which we will be able to generate reports for specific scenarios under the same tag.

We can also provide multiple tags as values separated by commas as shown below .Tags are define in our runner class like this:

tag6

Let’s discuss about tag how it will work for cucumber. We can tag a scenario or a feature by putting an annotation as tag on the line before the Scenario keyword, like this:

tag

Even, We can add multiple tags for same Scenario separated with spaces: like this:

tag2

If we want  to combine all the scenarios in one feature, for this we have to tag the feature at the beginning of the feature then all the Scenarios will inherit the same tag.Along with this, we can still tag a single scenarios as well.

tag5

When we define multiple  tags in runner class in below form ,it will be defined with the use of logical operator:
1. tags = {“@tag”, “@tag1”} : means AND condition. –It says that scenarios matching both these tag needs to be executed.
2. tags = {“@tag1, @tag2”} : means OR condition. — It says that scenarios matching any of this tag needs to be executed.
Why do we require Tagging in Cucumber and advantages of tags:
  • By using tags,  we can easily organize our feature and scenarios.
  • Any string literal may be used as a tag in any scenario or entire feature.
  • Feature can have multiple tags associated with it.
  • Be aware that tags are heritable within Feature files.
  • Different reports can be generated as per the requirements and the tags will be provided correspondingly.

In next tutorial we will get to know about Background…

Written by 

Principal Architect at Knoldus Inc

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading