Writing BDD Test Scenarios with Chat GPT

Didem Çiçek Bay
7 min readJun 12, 2023

--

Behavior Driven Development (BDD) is a branch of Test Driven Development (TDD). BDD uses human-readable descriptions of software user requirements as the basis for software tests.

Here’s an example of a Behavior Driven Development (BDD) scenario for an e-commerce application using the Gherkin syntax;

Gherkin is a business-readable, domain-specific language used for describing the behavior of software systems in a structured format. It is primarily used in Behavior Driven Development (BDD) to write scenarios and acceptance criteria in a human-readable manner.

Gherkin uses a set of keywords to define the structure and components of a scenario. The main keywords include:

Feature: Represents a high-level feature or functionality of the system.

Scenario: Describes a specific test scenario or use case.

Given, When, Then: These keywords are used to describe the steps of the scenario.

Given: Represents the initial state or preconditions of the scenario.

When: Represents the specific action or event being performed.

Then: Represents the expected outcome or result of the action.

Gherkin scenarios are written using a Given-When-Then structure to ensure clear communication and understanding between stakeholders, developers, and testers. It promotes collaboration and shared understanding of the desired system behavior.

Gherkin scenarios are written in a structured format using plain text, making them easy to read and understand. They provide a shared language that can be used by all stakeholders, including business analysts, developers, and testers, to communicate and collaborate on the desired system behavior and It can be executed using various BDD frameworks, which parse the Gherkin syntax and automate the execution of the scenarios as tests, helping to ensure that the system behaves as expected.


Feature: Shopping Cart Management
As a customer
I want to add and remove items from my shopping cart
So that I can purchase the products I desire

Scenario: Add Item to Shopping Cart
Given I am a registered user
And I am logged in to the e-commerce application
And I have a product with the name "iPhone 12"
When I navigate to the product page of "iPhone 12"
And I click the "Add to Cart" button
Then the "iPhone 12" should be added to my shopping cart
And the shopping cart should display a total of 1 item

Scenario: Remove Item from Shopping Cart
Given I have added the "iPhone 12" to my shopping cart
When I navigate to my shopping cart
And I click the "Remove" button next to the "iPhone 12"
Then the "iPhone 12" should be removed from my shopping cart
And the shopping cart should display no items

Scenario: Update Quantity of an Item in Shopping Cart
Given I have added the "iPhone 12" to my shopping cart
When I navigate to my shopping cart
And I change the quantity of the "iPhone 12" to 2
Then the quantity of the "iPhone 12" in my shopping cart should be updated to 2

Scenario: Apply Discount Code to Shopping Cart
Given I have added items to my shopping cart
And I have a valid discount code "SUMMER2023"
When I enter the discount code "SUMMER2023" in the appropriate field
And I click the "Apply" button
Then the discount should be applied to my shopping cart
And the total amount should be recalculated with the discount

Scenario: Proceed to Checkout
Given I have added items to my shopping cart
And I have provided the required shipping and billing information
When I click the "Proceed to Checkout" button
Then I should be redirected to the checkout page
And my order details should be displayed for review.

In the example above, we have scenarios covering different aspects of managing a shopping cart in an e-commerce application, such as adding products, removing products, updating quantities, applying discounts, and proceeding with checkout. Then each scenario follows the given structure to define the starting context.

It is possible to enrich your BDD scenarios with Chat GPT!

Incorporate the user’s journey into the entire scenario, just like the user does in real time, and also break down each scenario, just don’t write anything over the top! (Especially if you are using the free Chat GPT versions) Add all the positive and negative scenarios and use the tables if necessary to provide the data.

Example;

Write BDD scenario to open a bank account in XYZ with following criteria

-[] User should be aged above 18 years

-[] User should be verified via Xr card and Ration card or atleast passport or driving

licence

-[] If user does not have Aadhaar card, then he should have combination of passport and

ration card.

-[] If user does not have Aadhaar card, then he can have combination of driving licence and Ration card

-[] If User don’t have both Aadhaar card and passport, then he cannot open account

-[]User can open account online via online banking from computer -[] Supported browsers are chrome, Firefox and Safari -[] Opera, Edge chrome and Brave browsers are not supported

-[] Windows 10 and above are supported -[] Linux Kernel version should not be below 4

-[] MacOS should be Ventura

-[] User can open account in kiosk

-[] This feature is currently available in select metro cities in India, hence not applicable for

users

-[] If the opening of account fails, it should give a prompt with continuation number to open the account from branch

-[] Telephone banking should also support opening account with the continuation number

-[] Online banking does not support opening account with continuation number

-[] Mobile banking supports opening account with continuation number only in Android -[] iOS support for mobile banking with continuation

number is coming next month

-[]User can open account from branch

-[]User should accept all terms and conditions

-[] User can open account online via Mobile app in android

-[] While opening mobile app, they should always ignore the splash screen -[] User can open account online via Mobile app in iOS

-[] Ensure the splash screen is NOT visible while opening the iOS app, since its bug in the release

-[] The Mobile App supports only iOS 12 and above and in android for Android 5 and above.

Feature: Bank Account Opening
As a customer
I want to open a bank account in XYZ
So that I can manage my finances effectively

Scenario: Opening a Bank Account Online from Computer
Given I am above 18 years old
And I have the required identification documents
And I have access to a computer with a supported browser
When I visit the XYZ bank website
And I click on the "Open Account" button
And I provide all the necessary information
And I accept the terms and conditions
Then my bank account should be successfully opened
And I should receive a confirmation email

Scenario: Opening a Bank Account at a Kiosk
Given I am above 18 years old
And I have the required identification documents
And I am in a metro city where the kiosk service is available
When I locate a nearby bank kiosk
And I follow the on-screen instructions
And I provide all the necessary information
And I accept the terms and conditions
Then my bank account should be successfully opened
And I should receive a confirmation SMS with a continuation number

Scenario: Opening a Bank Account via Telephone Banking
Given I am above 18 years old
And I have the required identification documents
And I have the continuation number provided in case of failed online account opening
When I call the telephone banking helpline
And I provide all the necessary information, including the continuation number
And I accept the terms and conditions
Then the customer service representative should assist me in opening the bank account
And my bank account should be successfully opened
And I should receive a confirmation letter by mail

Scenario: Opening a Bank Account from a Branch
Given I am above 18 years old
And I have the required identification documents
When I visit a nearby XYZ bank branch
And I provide all the necessary information to the bank staff
And I accept the terms and conditions
Then the bank staff should assist me in opening the bank account
And my bank account should be successfully opened
And I should receive a printed confirmation document

Scenario: Opening a Bank Account via Mobile App on Android
Given I am above 18 years old
And I have the required identification documents
And I have an Android device with the XYZ bank mobile app installed
When I open the XYZ bank mobile app
And I provide all the necessary information
And I accept the terms and conditions
And I ignore the splash screen if it appears
Then my bank account should be successfully opened
And I should receive an in-app confirmation notification

Scenario: Opening a Bank Account via Mobile App on iOS
Given I am above 18 years old
And I have the required identification documents
And I have an iOS device with the XYZ bank mobile app installed
And today is the next month when iOS support for mobile banking with continuation number is available
When I open the XYZ bank mobile app
And I provide all the necessary information
And I accept the terms and conditions
And the splash screen is NOT visible
Then my bank account should be successfully opened
And I should receive an in-app confirmation notification

In addition, it is possible to direct ChatGPT by asking the right questions, you can look at the examples below.

Thanks.

Didem

--

--