Pages

Cucumber Tags ?

What are cucumber Tags?

In cucumber, we can execute only specific scenarios by using cucumber tags.

We can place the @tags only above Gherkin keywords:
  • Feature
  • Scenario
  • Scenario Outline
  • Examples
we can't place the @tags above Gherkin keywords Background or steps (Given, When, And, Then and But)

Let's say I have 3 scenarios Smoke, regression, sanity with step definitions implemented, and tagged those scenarios like below:

FirstFeatureFile.feature
Feature: Demo on cucumber framework
  Description: The purpose of this feature is explain cucumber tags

  @smoke
  Scenario: This is Smoke Scenario
    Given I am in Smoke Scenario

  @regression
  Scenario: This is Regression Scenario
    Given I am in Regression scenario

  @sanity @smoke
  Scenario: This is Sanity Scenario
    Given I am in Sanity and smoke scenario
Above scenarios step definitions implemented like below:
@Given("I am in Smoke Scenario")
public void iAmInSmokeScenario() {
    System.out.println("I am in Smoke Scenario");
}

@Given("I am in Regression scenario")
public void iAmInRegressionScenario() {
    System.out.println("I am in Regression Scenario");
}

@Given("I am in Sanity and smoke scenario")
public void iAmInSanityAndSmokeScenario() {
    System.out.println("I am in Sanity and Smoke Scenario");
}
Now, Run only the scenarios with tags @smoke from Runner file like below:
cucumber tags
cucumber tags
Run only the scenarios with tags @regression from Runner file like below:
cucumber @tags
cucumber @tags

Run only the scenarios with tags @sanity from Runner file like below:
cucumber tags
cucumber tags
Run the scenarios using And condition from Runner file like below:
cucumber tags using And
cucumber tags using And
Run the scenarios using or condition from Runner file like below:
cucumber tags using or
cucumber tags using or
Run the scenarios using not condition from Runner file like below:
cucumber tags using not
cucumber tags using not

We can conclude scenarios executed based on @tags like below:
cucumber @tags
cucumber @tags
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.