This example will go over the basic structure of a Cucumber feature file in Gherkin. Feature files use several keywords in the basic syntax.
Lets look at the basic keywords:
All keywords must be on a new line and must be the first word on a new line in order to be recognized by the Gherkin parser. The Feature and Scenario keywords must have a colon immediately after, as expressed in the example below. Given, When, Then, and And do not require a colon.
In addition to keywords, you can write descriptions and comments. Descriptions occur after the keyword but on the same line, where as comments occur on lines underneath the keywords. When writing Feature comments, it is customary to provided explicit rules outlining edges and conditions that lead to different outcomes of behaviors.
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
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.
Given the user is on the login page
When the user signs in with valid credentials
Then the user should be logged in