Misconceptions of Gherkin

Diseno sin titulo 6

Gherkin is a widely-used language for specifying the behavior of software systems in a structured and readable format. It is often used in conjunction with Behavior-Driven Development (BDD) frameworks to create tests that are based on the desired behavior of the system. However, despite its popularity, many people use Gherkin in the wrong way for automation purposes, leading to misconceptions about its purpose and benefits.

One common mistake is to treat Gherkin as a scripting language. For example, instead of describing behavior, the scenario might describe the specific implementation steps needed to complete the test. Here’s an example of a bad use of Gherkin:

 

Scenario: Login to the application

Given I am on the login page

When I enter my username “user1” and password “pass1”

And I click the “Login” button

Then I should see the dashboard page

 

In this example, the scenario is too specific and includes implementation details. A better way to write this scenario would be to focus on the behavior of the system and the desired outcome, like this:

 

Scenario: User can login to the application

Given I am on the login page

When I enter valid login credentials

And I click the “Login” button

Then I should be redirected to the dashboard page

 

Another common mistake is to use Gherkin to create highly specific test scripts. For example, the scenario might include implementation details that should be left to the test code. Here’s an example of a bad use of Gherkin:

 

Scenario: Verify that the email address field on the registration page is mandatory

Given I am on the registration page

When I enter my first name “John”, last name “Doe”, and email address “johndoe.com”

And I click the “Submit” button

Then I should see an error message that says “Please enter a valid email address”

 

In this example, the scenario includes specific implementation details, such as the email address that is entered. A better way to write this scenario would be to focus on the behavior of the system and the desired outcome, like this:

 

Scenario: Email address field is mandatory on the registration page

Given I am on the registration page

When I leave the email address field blank

And I click the “Submit” button

Then I should see an error message that says “Please enter a valid email address”

To use Gherkin effectively, it is important to focus on the behavior of the system and the desired outcomes, rather than on the specifics of how the system works. This means that Gherkin scenarios should describe what the system is supposed to do, not how it should do it. Detailed implementation instructions belong in the test code, not in the Gherkin scenarios.

Another important aspect of using Gherkin effectively is to involve all stakeholders in the process. This means that developers, testers, and business analysts should work together to create Gherkin scenarios that accurately reflect the desired behavior of the system. By involving all stakeholders in the process, the team can ensure that the scenarios are complete, accurate, and testable.

Gherkin is a powerful tool for describing the behavior of software systems in a way that is understandable and actionable by all stakeholders. However, it is important to use Gherkin in the right way and avoid common misconceptions. By focusing on behavior and involving all stakeholders in the process, Gherkin can be used effectively to create high-quality tests that accurately reflect the desired behavior of the system.

About

 

Hi There, I’m Nicolas, I’m 34 years old and I have been a Tester for more than 13 years. I started as a Manual Tester and then changed to Test Automation Engineer. I had many experiences throughout my life with different code languages such as Java, C#, or JS and using many different Automation technologies such as Selenium WebDriver, Appium, or Protractor. Right now I’m learning more about how to Automate the entire team to deliver more quality products.