×
☰ See All Chapters

Cucumber Tags

  • If you want to run a specific feature or specific scenario you can tag a unique id to those. Cucumber allows you to use tags as a filter to pick out specific scenarios to run or report on. 

  • You can tag any scenario by adding tag name prefixed with @ character. 

  • Tag should be added on the line before the Scenario keyword, like this: 

Feature: Login

  @MainLogin

  Scenario: Successful Login to the page

    Given I open Chrome browser

    When I navigate to login page

    Then Login page should be displayed

  • You can set any number of tags to scenario as below: 

Feature: Login

  @MainLogin @LaunchLogin

  Scenario: Successful Login to the page

    Given I open Chrome browser

    When I navigate to login page

    Then Login page should be displayed

  • By putting tag to Feature instead of Scenario, we can tag all the scenarios in a feature at once. All the scenarios will inherit the tag. But you can still tag individual scenarios as well. 

@LaunchBrowser

Feature: Login

  @MainLogin @LaunchLoginPage

  Scenario: Successful Login to the page

    Given I open Chrome browser

    When I navigate to login page

    Then Login page should be displayed

  • You can tag Scenario Outline elements also. 

Feature: Login

@LoginProcess

  Scenario Outline: Login Check

    Given I open Chrome browser

    And I navigate to login page

    When I click on login option

    And I provide username as <UserName> and password as <Password>

    And I click on login button

    Then <Outcome>

 

    Examples: Successful login

      | UserName                 | Password | Outcome                                  |

      | manu.m@tools4testing.com | *****    | Login success window should be displayed |

      | advith@tools4testing.com | *****    | Login success window should be displayed |

 


All Chapters
Author