What Is BDD Framework and Why to choose Cucumber?
Behaviour Driven Development (BDD) Framework enables technical and non-technical person to start from same platform, where product owner or manual QA or any other team member can write usecases/test steps in plain English and respective person can automate same steps. Product owner or manual QA can run the testcases they written in English language and behind the scene the script/code will execute. BDD mainly focuses on the behaviour of the product and user acceptance criteria. Cucumber is one of the best tools used to develop in the BDD Framework. Automation QA/Dev can write code in various languages like Java, Python, Perl, etc, Cucumber supports various languages. Cucumber uses Gherkin, an ordinary language parser, that permits writing scripts in English that can be easily understood. It is used to run the acceptance tests written in BDD.
Main components in Cucumber :
- Feature file : It’s a file, where product owner or any technical/non-technical person can write scenarios and respective steps which can be executed. Extension for Feature file is '.feature'
- Step Definition file : For each steps written in feature file there should be respective piece of code written, which will run behind the test steps. Step Definition contains respective code for the test steps written in feature file. Extension for Step Definition file is '.java'
- Test Runner file : It’s an entry point for the execution, where the location for Feature file and Step Definition should be defined, We can define tagging, reporting and other setting in test runner file. Extension for Test Runner file is '.java'
Features: Feature is a use case that describes the module under test. The feature is composed of the following details.
- The keyword ‘Feature:’ is appended before the name of the feature.
- The feature name is written beside the feature keyword.
- An optional description is also written below the feature to describe the crux of the feature.

Test scenarios are written in Feature file using Given, When, Then, And, But keyword
Given steps are used to describe the initial context of the system - the scene of the scenario. It is typically something that happened in the past or pre-requisite for test.
When steps are used to describe an event, or an action. This can be a person interacting with the system, or it can be an event triggered by another system.
Then steps are used to describe an expected outcome, or result. We can use assertion here and can get result as Pass, Fail or Skip
AND If you have successive GIVEN/ WHEN/ THEN statement, you can use AND instead of writing GIVEN/WHEN/THEN every time

Step Definition File :
A Step Definition is a small piece of code with a pattern attached to it or in other words a Step Definition is a java method in a class with an annotation above it. An annotation followed by the pattern is used to link the Step Definition to all the matching Steps, and the code is what Cucumber will execute when it sees a Gherkin Step. Cucumber finds the Step Definition file with the help of the Glue code in Cucumber Options.

Test Runner File :
In Cucumber, the test runner file executes the Cucumber feature files and coordinates the steps defined in those feature files with the corresponding step definitions. We can define pretty good reports in plugin of Cucumber options

Cucumber Reporting :
Cucumber gives us the capability to generate reports as well in the form of HTML, XML, JSON & TXT. Cucumber frameworks generate very good and detailed reports, which can be shared with all stakeholders. There are multiple options available for reports which can be used depending on the requirement.
Please find below an example report

Benefits of Cucumber Framework :
- Enhances communication among the members of a cross-functional product team
- Focuses on defining ‘behaviour’ rather than defining ‘tests’
- Helps reach a wider audience by the usage of non-technical language
- It enables you to understand how the system should perform from the developer’s and customer’s perspective
Conclusion :
In summary, Cucumber and BDD in general can be very useful, especially for testing, both manual and automated. However, it's important to know the exact situations where this solution works with the least amount of headaches.