Click here to Skip to main content
15,798,825 members
Articles / Programming Languages / Java

Getting started with Cucumber Framework for automation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
17 Nov 2015CPOL3 min read 16.9K   4   5
Cucumber framework understanding with BDD approach

Introduction to Cucumber:

Cucumber is basically a framework which is used for testing the application where the testscripts are written in plain english language.Mostly it is used for Acceptance testing and Functional Testing. BDD(Behavior Driven Development) technique is used while writting testcases. 

Advantages of Using it:

Following are some of the advantages of using cucumber framework over using simple selenium framework.

1.It is very easy to understand the testcases for anyone(e.g Developer,Tester and Stakeholders).
2.Anyone can write the test cases because it is written in plain english.
3.The Test cases are stored in a .feature file which can be used for documentation purpose for the project.No need to write extra document for the features.

4.One more and very important feature of using Cucumber is ,it allows heavy reuse of code.


1.One must have understanding on core java.
2.One must be comfortable with using Selenium WebDriver.
3.I am assuming the reader is well acquanted with using Maven.

Basically We need three things to run the project with Cucumber.Those are listed below
1.Feature Files where the test scripts are written in plain english.
2.Step Definitions java class files where code resides
3.One Runner class which is used to run the Junit test.

How the Feature File looks like:

Image 1

This is a file with extension .feature and kept in the same package name where the Runner class is kept inside.e.g if you keep the Runner class in Steps package then you must keep the feature files in same package which is shown in the below image.


Image 2

The language in which features are written in feature file is called gherkin.

How the Step Definition file looks like

Image 3

This is also called a Step layer.Here definitions for all steps are provided.

How the Runner class looks like

Image 4

It is used to read the cucumber feature files and accordingly step definitions files are invoked. Here you can mention Format of the report in which you want ,I mean whether you want it in html format or json format,you can mention that.Also testcases can be tagged to run the same by skipping all other testcases which are written in the feature file.

How Feature file looks like using tags:

Image 5

Installation of Cucumber:

There is no such .exe file or anything needed to work with Cucumber.One thing you have to do is that you have to add a couple of dependencies in your pom.xml file inside the maven project.That's all what needed to work with cucumber.Mainly Cucumber-java,cucumber-junit,gherkin dependencies need to be added through pom.xml file.

How those dependencies look like:

Image 6

Once those dependencies are added,now you are ready to work with Cucumber.

One more extra addon on eclipse can be used for Cucumber to write the feature files which helps to signifies each and every properties of cucumber.

This can be added from eclipse >>Help>>Install new software by adding the text "Cucumber -" in Work With filed and clicking on Add button.

Image 7

This is the very brief description about getting started with Cucumber.Thanks for reading it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Tester / Quality Assurance
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralWaiting for an example with selenium Pin
ChandraSPola21-Nov-15 2:38
professionalChandraSPola21-Nov-15 2:38 
GeneralRe: Waiting for an example with selenium Pin
KishorM22-Nov-15 20:51
KishorM22-Nov-15 20:51 
GeneralRe: Waiting for an example with selenium Pin
KishorM23-Dec-15 22:42
KishorM23-Dec-15 22:42 
QuestionCode Pin
Anda Cristea18-Nov-15 9:02
Anda Cristea18-Nov-15 9:02 
AnswerRe: Code Pin
KishorM19-Nov-15 0:23
KishorM19-Nov-15 0:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.