Automation (Web) – Cucumber, Selenium and Java


This blog will help you to test web applications i.e. applications hosted on the web by using functional testing tool (selenium webdriver) with java and Behavior Driven Development (BDD) framework Cucumber.


What Is Cucumber?

Cucumber is a tool based on Behavior Driven Development (BDD) framework which is used to write acceptance tests for web application and mobile application. It allows automation of functional validation in easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc.

Dependencies to add pom.xml

Junit Dependency

JUnit plugin

Cucumber-Junit Dependency

cucumber-junit dependency

Cucumber-Java Dependency

Cucumber-Java dependency

Cucumber Basics

In order to understand cucumber we need to know all the features of cucumber and its usage.

  • Feature file
  • Step definition file

Feature File is an entry point to the Cucumber tests. This is a file where you will describe your tests in Descriptive language (Like English). It is an essential part of Cucumber, as it serves as an automation test script as well as live documents. A feature file can contain a scenario or can contain many scenarios in a single feature file but it usually contains a list of scenarios. All the feature files ends with .feature extension.

Sample feature file

google feature

A Step definition file is a collection of step definitions. 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 Glue code in Cucumber Options.

Sample defnition file

Setting up cucumber project

1  Create feature file 

  • Create a feature folder undersrc/test/resources named as feature
  • Create feature file under feature folder.

feature file

2  Create definition file

  • Create a package undersrc/test/java named as test
  • Create a java class file under cucumber.test package named as java

definition file.PNG

3  Create Junit runner class

  • Create a java class file under cucumber.test package named as java

Junit runner.PNG

4  Copy below code and paste in


5  Right click on and run as Junit Test

  • Html and json Report will be generated under target folder after the run

html report.PNG

  • Console output will be like below


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s