QA Tutorials


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 :

  • Feature
  • Scenario
  • Background
  • Given
  • When
  • Then
  • And & But

How to use these Gherkin components in cucumber testing?

  1. First, identify the scenario which you want to automate.
  2. Add a feature file for the scenario
  3. Create a test Runner class that will execute feature file
  4. Create a step definition which has to be linked to the java code.

How to create a feature file in Cucumber?

  1. Setup a cucumber eclipse plug in.
  1. Create a new Maven project in Java EE in new project.
Add new source folder in Cucumber project
  1. Enter the details of the maven project like Group id etc.
New Package in resources folder
  1. 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.
Cucumber feature file in eclipse project
  1. Next create step definitions under this. Create a java class by clicking on the folder called step definition.
  1. 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.

  1. Copy the snippets and paste in the step definition screen under the java class.
  1. 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.
  1. Import the package of cucumber and all the errors of the methods will be eliminated.
  1.  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.
  1. 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.
Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button