For the purposes of documentation, you may want to filter test plans or scenarios by categories. Developers may want to run tests based on those same categories. Gherkin allows you to categorize Features as well as individual Scenarios via the user of Tags. In the example below, notice the above the Feature keyword is the Tag "@Automation". Gherkin recognizes this as a tag by the user of the "@" symbol. In this example, the engineer wants to make it clear that these tests are used for automation, where not every test is automate-able, some tests must be done by manual QA.
Notice as well that the tag @Production has been added to the scenario testing user lock out. In this example, this is because this scenario is only active in the production environment of the application. The developers don't want their sandbox accounts locked out during development. This tags allows them to enforce that this test will only be ran against the production environment.
Lastly, the Scenario Outline has the tag @Staging. For the purposes of this example, this is because the accounts being used are staging accounts and will not working in the other environments. Like the @Production tag, this ensures that these tests will only be ran in the Staging environment.
These are just a few examples of where, how, and why you might use tags. Ultimately these tags are going to have meaning to you and the developers and can be anything and used to categorize however you see fit.
@Automation
Feature: Product Login
As a user, I would like to be able to use my credentials to successfully
login.
Rules:
- The user must have a valid username
- The user must have a valid password
- The user must have an active subscription
- User is locked out after 3 invalid attempts
- User will get a generic error message following
login attempt with invalid credentials
Background: The user starts out on the login page
Given the user is on the login page
Scenario: The user successfully logs in with valid credentials
This scenario tests that a user is able to successfully login
provided they enter a valid username, valid password, and
currently have an active subscription on their account.
When the user signs in with "valid" credentials
Then the user should be logged in
Scenario: The user attempts to log in with invalid credentials
This scenario tests that a user is not able to log in when
they enter invalid credentials
When the user signs in with "invalid" credentials
Then the user should be logged in
@Production
Scenario: The user is locked out after too many failed attempts
This scenario validates that the user is locked out
of their account after failing three consecutive
attempts to log in
When the fails to log in 3 times
Then the user should be locked out of their account
@Staging
Scenario Outline: The user successfully logs in with their account
This scenario outlines tests in which various users attempt
to sign in successfully
When the user enters their <username>
And the user enters their <password>
Then the user should be successfully logged on
Examples:
| username | password |
| frank | 1234 |
| jack | 4321 |