Using Behavior Driven Development with Gherkin-Based Syntax

Modified on Wed, 11 Sep at 2:19 PM

TABLE OF CONTENTS

1. Overview

2. Example Scenario

2.1 Verification steps

1. Overview

This article explains the Given-When-Then syntax for behavior-driven development (BDD), provides an example scenario for user registration on Amazon, and outlines verification steps.

2. Given-When-Then Syntax

The Given-When-Then syntax is a commonly used structure for writing test cases in behavior-driven development (BDD). It is used to describe the desired behavior of an application under test in a clear, concise, and consistent manner.
The structure comprises of three main components:

  • Given: This section describes the initial state or context of the system. It sets the scene for the scenario being tested.
  • When: This section describes the action or event that occurs. It specifies the trigger for the scenario being tested.
  • Then: This section describes the expected outcome or result of the scenario. It defines the acceptance criteria for the scenario being tested.

2. Example Scenario

Consider the following scenario.

Scenario: User Registration on Amazon

  • Given the user is on the Amazon registration page,
  • And there are fields for entering name, mobile number, password (with 6 characters), and verifying the mobile number,
  • And there is a "Verify Mobile Number" button,
  • And the user intends to register with a valid name, mobile number, and password.
  • When the user enters their name in the name text box,
  • And enters their mobile number in the mobile number text box,
  • And enters a password with 6 characters in the password text box,
  • And enters the same mobile number in the verify mobile number text box,
  • And clicks the "Verify Mobile Number" button.
  • Then the system should send an OTP (One-Time Password) to the provided mobile number,
  • And the system should display fields for entering the OTP,
  • And the user should enter the OTP received on their mobile number in the OTP text box.
  • And when the user clicks the "Create Your Account" button.
  • Then the system should validate the OTP entered by the user,
  • And if the OTP is valid, the system should proceed with the registration process,
  • And the user should be redirected to the account confirmation page.

These steps outline the expected behavior of the Amazon registration page when a user enters their name, mobile number, password, verifies the mobile number, enters the OTP, and creates their account.

In the preceding example, And and But additional conditions are also used. where  

And is used to add additional conditions or actions within the same clause. It is used to extend the current context or action without starting a new clause.

But is used to introduce an alternative or exception to the expected outcome in the scenario. It is often used to indicate a deviation from the main flow.

2.1 Verification steps

The following verification steps are from the preceding example

  1. Ensure the user is directed to the Amazon Registration Page.
  2. Confirm the presence of the Name, Mobile Number, Password, and Verify Mobile Number fields.
  3. Verify that the Name, Mobile Number, and Password fields accept user input.
  4. Confirm that the Password field accepts a minimum of 6 characters.
  5. Ensure the Verify Mobile Number button is present.
  6. Click the Verify Mobile Number button.
  7. Verify that an OTP is sent to the provided mobile number.
  8. Confirm the presence of the OTP field for entering the received code.
  9. Enter the OTP code received on the mobile number into the OTP field.
  10. Ensure the "Create Your Account" button is visible.
  11. Click the "Create Your Account" button.

These verification steps ensure that the registration process on the Amazon Registration Page functions as expected, including OTP verification and account creation.



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article