Cucumber
Hi everyone, I want to talk about the Cucumber Test framework that I have been wondering about for a long time. Initially, I was curious about what was Cucumber and why it was called a name like Cucumber to begin with. As I learned, I realized it is a very interesting topic, and I have been passionate about it since then. So, let’s get started
Our first question is ‘What is Cucumber?’
To mention briefly, Cucumber is the BDD Framework for running automated tests.
So, what is BDD?
Nowadays, to get better advantage of the software testing process, organizations are taking a step forward and implement important acceptance test scenarios while development is still in progress. This approach is commonly known as Behavior Driven Development (BDD).
Behavior Driven Development gives us the opportunity to create test scripts from the perspective of a developer and a customer as well. In the beginning of the development cycle, developers, project managers, QAs, user acceptance testers and the product owners (stockholder), all get together and brainstorm about which test scenarios should be passed in order to call the software/application successful. This way they come up with a set of test scenarios. All these test scripts are in simple English language, so these scenarios serve the purpose of documentation as well.
The described approach above is actually the definition of Gherkin. Let’s look into what that is in detail.
What is Gherkin?
It is a Business Readable, Domain Specific Language that lets you describe software’s behavior.
To exemplify that;
Business analyst describes the test scenario as follows.
-Pop up messaged is displayed and errors are gone on button clicked.
Then, the developer reading this, starts coding understanding that as;
-Pop up messaged is displayed when button clicked and errors are gone
After the development process is completed, Quality Analyst starts testing perceiving it as;
-Pop up messaged is displayed only when button is clicked and errors are gone.
And project fails in the end. In this case, Gherkin is here to help standardizing everything.
So how?
- Given: Preconditions are mentioned in the Given keyword
- When: The purpose of the When Steps is to describe the user action.
- Then: The purpose of Then Steps is to observe the expected output. The observations should be related to the business value/benefit of your Feature description.
Before Gherkin

After Gherkin

In addition to there, we have And and But keywords. The definitions for these keywords are;
- And: This is used for statements that are an addition to the previous Steps and represent positive statements.
- But: This is used for statements that are an addition to previous Steps and represent negative statements.
Keywords Used in Cucumber:
- Scenario
- Feature
- Feature file
- Scenario outline
- Step Definition
Scenario

Feature and Feature File
Feature represents Business requirement. Feature File acts as a Test Suite which consists of all Scenarios. In Cucumber, Feature files contain Scenarios. We can simply create feature file with. feature extension. Scenarios belonging to specific area of Application will be grouped into one Feature file
The text that immediately follows the Feature keyword, and is in the same line, is the Title of the Feature file
Feature file should contain either Scenario or Scenario Outline. The naming conventions for Feature files should be lowercase with. feature extension
Give an example;
Feature: Credit card payment
Scenario: Make Minimum Due payment
Given user is on Pay credit card page
When user fills all details and select Minimum amount option
And User clicks on Pay button
Then Credit Card confirmation page is displayed
Scenario: Enter another Amount as 0
Given user is on Pay credit card page
When user fills all details and select other Amount and enter 0
Then Credit Card confirmation page is not displayed
But error message is displayed
And finally, let’s talk about Step Definition. We can simply define it as a class that contains all the feature steps inside.
Thats all what I wanted to share. Have a good day.
Thank you