Writing Gherkin-style tests with Cucumber
In the previous section, we learned how to use Cypress to test API responses. In this section, we will learn how to create Gherkin-style tests with Cucumber. Gherkin is a behavior-driven development language used by Cucumber to describe test scenarios' behavior in a plain-English format. Tests written in Gherkin also make it easier for software teams to communicate and provide context for test cases with business leaders.
Gherkin uses the following keywords: Feature
, Scenario
, Given
, When
, and Then
. Feature
is used to describe the thing to build, such as a login page, for example. Scenario
describes the user flow for the feature. For example, a user can enter a username, password, and click Login to navigate to their profile page.
The Given
, When
, and Then
keywords describe the scenario at different stages. We could write a complete Gherkin test for a login feature like so:
Feature: Login Scenario: A user can enter...