Hi All! Welcome to a series of Cucumber Framework with Java.
With lots of buzz in the IT industry, Cucumber has acquired a trendsetter position. Let’s have an insight of cucumber in this and coming series of blogs. Happy learning.
Why Cucumber Framework?
So far, in my previous blogs, I have covered the Selenium topics with TestNG. It is also known as a TDD approach. Here, with Cucumber, we are going to follow a BDD approach i.e Behaviour Driven Development. In plain context, I would say BDD covers the behavior of the framework or behavior of the test cases or the use cases.
The behavior here specifies a simple language which is called Gherkin. Therefore, Gerkin defines the BDD framework and it is also called the feature language. Also,this way is the simplest way to make things understand to non-technical persons.
Gherkin language helps to facilitate wall-to-wall within the team members. Hence, It is easy to interact directly with the development code and also quite easy to understand by business stakeholders.
Advantages of Cucumber Framework:
– Less code-centric
– Supports multiple languages
– Easy integration with Selenium
Components of Cucumber
There are three major components in a cucumber framework. These are :
- Feature file
- Step definitions file
- Test Runner File
Let’s first talk about all the components one by one.
Feature File :
To begin with,we call it feature file because it has ‘Feature’. ‘Feature’ keyword specifies what kind of feature the file contains. Specifically, we have these very incomplex and self-explanatory keywords used in this file.
To illustrate, Consider a Scenario :
Here, feature keyword defines the detail of the functionality implementation. There can be multiple scenarios in one feature File. Given, When, Then defines the actual test steps execution.
Did you know? A feature file can contain a maximum of 10 scenarios
Step Definition File :
In the step definition file, we will be having our selenium code and java code along with the annotations. Corresponding to each keyword in the feature file, we have the step definition i.e there can be a method in step definition file which is mapped to each step in the feature file.
However, step definition files are written in java or any programming language.
For instance, considering the same scenario :
Test Runner :
Finally, in Test Runner file we write the actual selenium code which interacts with web elements and drives your test scripts. Thus, it is like the link or bridge between feature and step definition file.
For example,something like this for the same scenario :
Additionally, In next blog we shall see the complete setup of above files in eclipse