As we continue writing .feature files and scenarios (aka. test cases) , we might end up in large # of files at some point. At that point, if we would like to slice and dice our tests meaning, we want to be able to run a certain set of scenarios based on a criteria, tags are one of many wonderful solutions that Cucumber gives us (Think of tags as “Test Lab” in Quality Center, where we can pull test cases from Test Plan and execute a certain set of test cases)
So what might be some criteria and rules on which we want to group test cases (statically at one time or come back later and group in a different way more dynamically). Some of the attributes on which we can tag scenarios are:
- Smoke, Regression, Sanity etc.
- Release type (beta, alpha, production etc.)
- fast, slow, medium etc.
- parallel, not_parallel
- Really however you want to tag….
Piece of Advice
In my experience, making a decision on the criteria takes a long way in making scenarios simple (of course there is always a way to remove or replace an existing tag. We can search+replace on entire project very easily). So for example [Sanity,Smoke,Regression], [fast,slow,medium] are good tags.
So how do I tag ?
Type “@<tag_name>” at the top of Feature or Scenario – That is it!
Let’s see some examples
Tag a feature
Here we tagged @slow at the top of Feature – The tag applies automatically to all of the scenarios on the feature file
Tag a scenario
Place the tag right at the line above the scenario. Here we tagged a scenario with @sanity @beta3 (Separate multiple tags with spaces).This means that the tags [@slow @sanity @beta3], all of them apply to the scenario. So if we run any of the tags, the scenario will get picked up
There are many more best practices and guidance around how tags should be used and where do they apply the best, which will be covered as part of online tutorial if you register for the course
Now Let’s execute !
There are other ways to execute as well. Also we can combine tags using AND, OR , NOT etc. and that gives a lot of power to slice and dice the tests.