Cucumber is an open source tool that supports Behaviour Driven development. It explains the given application into simple like English language called Gherkin.
The Gherkin includes components like :
- And & But
How to use these Gherkin components in cucumber testing?
- First, identify the scenario which you want to automate.
- Add a feature file for the scenario
- Create a test Runner class that will execute feature file
- Create a step definition which has to be linked to the java code.
How to create a feature file in Cucumber?
- Setup a cucumber eclipse plug in.
- Create a new Maven project in Java EE in new project.
- Enter the details of the maven project like Group id etc.
- Type the scenario for home page. This is an example to verify the website called orange HRM home page by launching the chrome browser. This is a feature file, very simple and easy to write. Any body can write this feature file as it is easily understandable by others.
- Next create step definitions under this. Create a java class by clicking on the folder called step definition.
- Create all the methods for the step definition. To do that, go to feature file Right click -> select run feature file. When the feature file gets executed it fails and provides a suggestions of missing methods in the form of snippets.
According to the output created by the feature file while running all the scenario
steps get failed and missing methods are provided for the implementation.
- Copy the snippets and paste in the step definition screen under the java class.
- Whatever we have copied is just a outer structure. We have to type it, in order to eliminate errors for each step definition method which is created by executing the feature file. Once we start typing on the component a list of package is provided.
- Import the package of cucumber and all the errors of the methods will be eliminated.
- Write the codes properly for all the methods in the application, in order to implement the scenario. At the end of the file, then it is automatically created and it can also be changed to And.
- Lastly run the feature file as usual mentioned in the above screenshot. We can see, in the below mentioned, that there is one scenario and four steps which is passed.