Tags In Cucumber Framework

Reading Time: 2 minutes

In this blog, we are going to discuss Tags In Cucumber Framework. When we work on any real-life project, we have a huge number of scenarios in a single feature file and can have many feature files. Generally we create separate feature files based on various features in our real-life project.

When we have scenarios and features which runs every time. But when we need to run seperate scenarios in a single feature file or different scenarios of different feature files. In this case we need to know Tags In Cucumber Framework.

Why we need Cucumber Tags:-

In real-life projects, there can be a situation when we need to run certain kinds of tests. Smoke test, sanity test, regression test, and End to End test are a few of them which we need to execute at times.

To solve this problem, we can copy-paste our various scenarios and run them separately. Another way we can arrange them in order where we don’t need to do code duplicacy. And this kind of project requires huge maintenance costs.

To solve this, Cucumber has already provided a useful technique to organize our scenarios and its execution using tags in a feature files. To achieve this we need to define each scenario with various useful tags. Then we need to define in runner file to execute which specific tag/s.

Syntax :- Go to test runner then in CucumberOptions as tags={“@SmokeTests”,”@SanityTests”,”@RegressionTests”}

Tags In Cucumber Framework in Runner File

After creating all the useful/necessary tags now its turn to tag all the scenarios accordingly. We need to mention the tag name just above the scenario in all the available feature files.

Example:-

 tags={"@SmokeTests","@SanityTests","@RegressionTests"}
Tags In Cucumber Framework in scenarioExample

How to ignore cucumber Tests:-

In real-life projects, we need to ignore some tests while running various tests. Cucumber provides a very good and useful feature for this. we have to “`” operator in front of any tag. This works for scenarios and features.

Example :-

 tags={"@SmokeTests,`@SanityTests,`@RegressionTests"}

Conclusion:-

In this way we can say that Cucumber Tags is one of the useful features. We can manage our real-life test execution by introducing various tags. Tags works provide us the power to reduce code duplicacy. we can tag one scenario to many different test execution cycles and provide a comprehensive way to manage test scenarios.

Refrences:-

https://www.javatpoint.com/, https://www.toolsqa.com/

Knoldus-blog-footer-image

Written by 

QA Consultant

Leave a Reply