Cucumber with TestNG & Selenium (Part-1) – BDD Framework


In this post, will discuss about What is Behavior Driven Development, Importance of Cucumber, Feature file, Step definition and Cucumber Options.

What is BDD?

Behavior Driven Development is a software development process that emerged from Test Driven Development. Behavior Driven Development is about implementing an application by describing it’s behavior from the perspective of its stakeholders and customers.

Advantages of Behavior Driven Development

  • Strong Collaboration
  • High Visibility
  • The software design follows business value
  • Ubiquitous Language
  • Software development meets user need
  • Lower costs

What is Cucumber?

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

Advantages of Cucumber

  • It helps to engage in the process the business stakeholders who are not able to easily perceive the code.
  • The Cucumber tool is oriented to the end users.
  • The way of the test writing ensures a rather easy code reusing in the tests.
  • The way of the test writing ensures a rather easy code reusing in the tests.

Cucumber with Selenium Architecture

The procedure of automation using Cucumber

In Cucumber, first we need to define the feature file, step definition and then test runner class.

  • In feature file, we will define the basic steps using Scenario, Given, When and Then keywords.
  • In step definition class, we will define the respective methods (implementation) for the steps which we have defined in feature file.
  • In test runner class, we will define, the feature file & step definition. After running the test runner class, the respective feature file and step definition class files will be run and results will be displayed.

Configure Cucumber

In Maven pom.xml, please add the below dependencies for Selenium, Cucumber and TestNG.

<!-- -->
<!-- -->
<!-- -->
<!-- -->

Feature file in Cucumber

A feature file is an entry point to the cucumber tests. In this file, we will describe the tests in descriptive language (Easily understandable language).

The keywords available in Gherkin as listed below.

Keyword Synonyms Description
Feature Business Need, Ability Begins a Gherkin file (Cucumber file).
Background Runs steps before scenario
Scenario Starts a new scenario
Scenario Outline Scenario Template Starts a new scenario with multiple examples
Given *, And, But Puts the system in a predefined state
When *, And, But Performs an action
Then *, And, But Tests for consequences
Examples Scenarios Lists examples for scenario outlines

Cucumber Options

@CucumberOptions are like property file or settings for your tests. We should include CucumberOptions in Test Runner class

Options available for @CucumberOptions

Options Purpose Default Value
dryRun true: Checks if all the steps have the Step Definition false
features set: The paths of the feature files { }
glue set: The paths of the step definition files { }
tags instruct: What tags in the feature files should be executed { }
monochrome true: Display the console output in much readable format false
format set: What all the report formats to use false
strict true: Will fail execution, if there are undefined or pending steps false
  features=“<Path of the feature file to be executed>”,
  glue=“<Path to the step definition package>”,
Format={“pretty”,”html:<HTML report folder>”,”json:<Path of Json report file”}
tags={“@<tag name>”}


About the course

NPN Training is counted among the top ten Selenium Training in Bangalore for providing the best Selenium training in Bangalore. Our selenium course content and syllabus is designed according to the industry requirement to accomplish everyone’s career goal.


Related Post
Selenium Grid – Test execution in Cluster (Part-3)... Parallel execution in Selenium Grid with Hub and Node(s) configuration Before starting the parallel execution part, you should know about Selenium Gr...


M.r Pradeep is QA expert working as a Research Analyst at NPN Training. He is having 12 years of experience in Quality Assurance with extensive of 4 years in Automation experience (Selenium, UFT, Rest Assured, Jmeter & Soap UI). He has helped the peers/students to understand and learn Automation with Selenium and API automation with Rest Assured with Hands-On approach.