Score 100% on the quiz to continue
Testing your first feature
Write your first feature file in Gherkin, the language Cucumber understands.
When using Cucumber together with automated testing tools such as Cypress, we write tests in a language known as Gherkin.
Gherkin is a domain-specific language that allows the use of some keywords to describe features and their behaviors.
Example:
# cypress/e2e/login.feature
Feature: Login
Scenario: successful login
Given I access the Login form
When I submit it with valid credentials
Then I see the logged-in features available- The
Featurekeyword defines the feature under test - The
Scenariokeyword describes the scenario, or test case - The
Givenkeyword defines the precondition of the test, that is, the initial state for that scenario to be tested - The
Whenkeyword defines the action (or actions) that exercise the application under test for a given scenario - The
Thenkeyword defines the expected result, that is, what should happen after the previous action (or actions) are executed - The
Andkeyword is an alias forGiven,When, orThen, and can be used when the precondition, action, or expected result has more than one step
Commands overview 📖
Below are the Gherkin keywords used in this lesson's exercise.
Feature
Defines the high-level feature or capability being described and tested.
Syntax:
Feature: <description>Example:
Feature: LoginScenario
Describes a single test case, representing one specific behavior of the feature.
Syntax:
Scenario: <description>Example:
Scenario: successful loginGiven
Defines the initial state or precondition for the scenario to be tested.
Syntax:
Given <step description>Example:
Given I access the Login formWhen
Defines the action or event that exercises the feature under test.
Syntax:
When <step description>Example:
When I submit it with valid credentialsThen
Defines the expected outcome after the action described in the When step.
Syntax:
Then <step description>Example:
Then I see the logged-in features availableAnd
An alias for Given, When, or Then. Use it to add a second (or third) step to the same part of the scenario, avoiding repetition of the same keyword.
Syntax:
And <step description>Example:
Feature: Login
Scenario: successful login
Given I access the Login form
And the form is empty
When I fill in my credentials
And I click the submit button
Then I see the logged-in features available
And the login form is no longer visibleExercise 🎯
- Inside the
cypress/e2e/folder, create a folder calledengagesphere/ - Inside the
cypress/e2e/engagesphere/folder, create a folder calledcookies/ - Inside the
cypress/e2e/engagesphere/cookies/folder, create a file calledcookies.feature - Finally, in Gherkin language, write a test for the scenario where the EngageSphere application's cookie consent banner is accepted, and another for when it's declined.
From the Cypress App, run the tests to ensure your implementation works.
If the Cypress App isn't open, use thenpm run cy:opencommand to open it.
When you run the tests, you should see an error indicating that the step implementation is missing. Don't worry about it. That's because we haven't implemented it yet. We'll do it in the next lesson.
Show the world what you learned 🌎
To show your professional network what you learned in this lesson, post the following on LinkedIn.
I am taking the course "End-to-End Testing with Cypress and Cucumber: The Definitive Guide 🥒" by @Walmyr Lima e Silva Filho at the @Talking About Testing School, where I learned about the Gherkin language for writing automated tests with Cypress and Cucumber. #TalkingAboutTesting #TATSchool #Cypress #Cucumber
👨🏫 Remember to tag me in your post. Here is my LinkedIn profile.
Quiz
What is the purpose of the `Given` keyword in a Gherkin scenario?
Coding Challenge
Write a Gherkin feature file that describes the scenario where a user accepts the cookie consent banner on the EngageSphere app.
Score 100% on the quiz to continue