Product Manager’s Perspective on Gherkin Script

tolga özdemir
3 min readAug 5, 2024

--

Streamlining Collaboration and Clarity in Product Management through Behavior-Driven Development

Photo by Jonathan Pielmayer on Unsplash

Gherkin is a language paradigm used in behavior-driven development (BDD) to generate test scenarios explaining software behavior. Product managers also use this popular approach to enhance communication between technical teams and other departments.

If your technical staff repeatedly complains, “You didn’t inform us of this request in that way,” or if your team makes many mistakes in explaining their perspectives, Gherkin may be a better option.

If you’re ready, let’s explain…

How to Use Given-When-Then Keywords?

The Given-When-Then sentences are used to write effective test scenarios. Those keywords serves to specify the context, action, and anticipated result of a feature. Because of their conversational tone, these documents make it easy for people without technical backgrounds to understand and communicate the features.

I will primarily concentrate on providing examples in English, however you have the option to express these statements in another language.

  • Given: Describes the initial context or state before an action occurs.
  • When: an action or event occurs, it specifies the trigger for the behavior.
  • Then: Specifies the desired result or outcome following the action.

When Should Gherkin Scripts Be Used?

It is particularly useful in several cases. For example, when the project requires coordination and cooperation among various teams. Or, when clear and precise documentation of user requirements is essential. It is also useful when all stakeholders need to have a shared understanding of functionality. Also, automating acceptance tests is essential for ensuring that features align with requirements.

When it comes to writing Gherkin specifications, it’s important to take a structured approach for clarity. Start with providing a comprehensive list of all possible scenarios. Begin by identifying all that is required for the feature. Provide a short and simple statement for each scenario. Then, describe the initial context before any action takes place for each scenario. Then, apply the “Given” keyword to establish the preconditions.

Determine the action or event that initiates the behavior. Clearly describe this action by using the “When” keyword. And then, specify the desired outcome or result following the action. When describing the expected state or output, you can use the keyword “Then”.

Additionally, you can use “And” to incorporate additional conditions or steps within Given, When, or Then blocks. However, you can use “But” to specify exceptions or variations in the conditions or outcomes.

Thoroughly examine each scenario to make sure that it is clear and comprehensive. Simplify the language to ensure maximum clarity and understanding for all stakeholders.

Simple Example

Feature: User Login

Scenario: Successful login with valid credentials
Given the user is on the login page
When the user enters a valid username and password
And clicks the login button
Then the user should be redirected to the homepage
And the user should see a welcome message

Scenario: Unsuccessful login with invalid credentials
Given the user is on the login page
When the user enters an invalid username or password
And clicks the login button
Then the user should see an error message
And the user should remain on the login page

More Complex Example

Feature: Shopping Cart Management

Scenario: Adding an item to the cart
Given the user is on the product page
When the user selects a product
And clicks the "Add to Cart" button
Then the item should be added to the shopping cart
And the shopping cart count should increase by 1

Scenario: Removing an item from the cart
Given the user has items in the shopping cart
When the user clicks the "Remove" button next to an item
Then the item should be removed from the shopping cart
And the shopping cart count should decrease by 1

Scenario: Updating item quantity in the cart
Given the user has items in the shopping cart
When the user changes the quantity of an item to 3
And clicks the "Update" button
Then the item quantity should be updated to 3
And the shopping cart total should reflect the updated quantity

Scenario: Checking out the cart
Given the user has items in the shopping cart
When the user clicks the "Checkout" button
Then the user should be redirected to the checkout page
And the shopping cart summary should be displayed
And the user should be able to enter shipping and payment information

If you have any questions or other points to contribute to the discussion, please leave a comment.

--

--

tolga özdemir

Internet professional, product manager, and a very curious man