top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

Getting Started with the Cucumber Tool

Apr 29, 2025
4 min read

In this blog we are going to learn about cucumber tool .Before starting with cucumber ,we need to know what is Behavior Driven Development(BDD)


What is Behavior Driven Development(BDD)?

BDD testing is the software testing practice of describing test steps in simple language so that both technical and non-technical stakeholders can have a shared understanding of the code.



A common BDD language is Gherkin. Here's a description of the Login scenario written in Gherkin:

Feature: User Login

Scenario: Successful login with valid credentials

Given the user is on the login page

When the user enters valid credentials

And clicks the login button

Then the user should be redirected to the dashboard

And see a welcome message

Lets dive into a popular BDD framework , the Cucumber tool.


What is Cucumber?

Cucumber is one of the most widely used BDD frameworks. It allows users to write test scenarios in Gherkin language, which is a simple, human-readable syntax. Gherkin is a domain-specific language for behavior descriptions.

Cucumber test automation makes use of two important files:

Feature file – Contains code written in Gherkin (plain English text)

Step definition file – Contains the actual code written by the developer

Language: Java, Ruby, JavaScript, Python, PHP, Perl, Swift, .NET, C++.


Features:

Supports feature files written in Gherkin syntax.

Extensive ecosystem with plugins and integrations.

Good support for multiple languages and platforms.


Cucumber integrates with various test runners and automation tools to execute these scenarios.



Types of Cucumber Tests

Cucumber testing can be used to test a variety of different types of applications. Here are some examples of the different kinds of Cucumber tests you can use:


Acceptance tests: These tests help you determine if an application meets the requirements the customer or client sets. Acceptance tests are typically written in Gherkin syntax.


Functional tests: These tests help you determine if an application is working as expected. Functional tests are typically written in a programming language like Ruby or JavaScript.


Integration tests: These tests help you determine if different parts of an application are working together as expected. Integration tests are typically written in a programming language like Ruby or JavaScript.


Unit tests: These tests help you determine if a specific unit of code is working as expected. Unit tests are typically written in a programming language like Ruby or JavaScript.


Why use Cucumber?

Cucumber simplifies test automation with its BDD approach, making tests more readable, collaborative, and

here are its key benefits.

Involving stakeholders becomes easier regardless of their programming knowledge.



Setting Up Cucumber (With Java Example)

Let’s get hands-on and set up a basic Cucumber project using Java and Maven.

Step 1: Prerequisites

Make sure you have the following installed:

Java (JDK 8 or above)

Maven

An IDE (like IntelliJ IDEA or Eclipse)


Step 2:Create a Maven Project

Create a new Maven project and add the following dependencies to your pom.xml:


<dependency>

<groupId>io.cucumber</groupId>

<artifactId>cucumber-java</artifactId>

<version>7.21.1</version>

<scope>test</scope>

</dependency>


Step 3: Write Your First Feature File

Create a .feature file under src/test/resources.

Example: Login Functionality

Scenario: Valid login

Given user is on the login page

When user enters valid username and password

Then user is redirected to the homepage


Step 4: Create Step Definitions

Now map those steps to Java methods in a class under src/test/java.


package stepDefinitions;


import java.io.IOException;


import org.testng.Assert;


import io.cucumber.java.en.Given;

import io.cucumber.java.en.Then;

import io.cucumber.java.en.When;

import pageObjects.LoginPage;

import utilities.ConfigReader;

import utilities.ExcelReader;

import utilities.LoggerLoad;


public class LoginStepDefinition {

LoginPage login Page = new LoginPage();

String ExpectedMessage;

ExcelReader excelUtils;

String actualMessage;

String expectedMessage;


@Given("user is on the login page")

public void user_is_on_login_page() {

System.out.println("User navigates to login page");

}


@When("user enters valid username and password")

public void user_enters_credentials() {

System.out.println("User enters credentials");

}


@Then("user is redirected to the homepage")

public void user_is_redirected_home() {

System.out.println("Login successful, redirected to homepage");

}



}

}



Step 5:Run Your Test


import io.cucumber.testng.AbstractTestNGCucumberTests;

import io.cucumber.testng.CucumberOptions;

import utilities.ConfigReader;

import utilities.DriverManager;

@RunWith(Cucumber.class)

@CucumberOptions(features = "src/test/resources")

public class TestRunner {

}


Report generation in Cucumber:


After test execution, it is also require to understand the output of the execution.

Cucumber uses reporter plugins to produce reports that contain information about what scenarios have passed or failed. Some plugins are built-in, others have to be installed separately.


let's learn to generate it as well.

When we execute Cucumber Scenarios, it automatically generates an output in the eclipse console. There is a default behavior associated with that output and we can also configure that output as per our needs also. So how do we modify the default behavior, let's see this now.


Pretty Report

The first plugin, we will talk about is Pretty. To implement this, just specify plugin = "pretty" in CucumberOptions. This is what the code looks like:


@CucumberOptions( plugin = { "pretty" } )

Complete TestRunner would look like this:


Cucumber Report



Conclusion:

Cucumber is a powerful tool for test automation, offering simplicity and flexibility through its natural language syntax. By combining it with tools like Selenium, testers can build robust, readable, and maintainable automated test suites. Whether you’re new to automation or looking to enhance your testing strategy, Cucumber testing provides an excellent foundation for Behavior-Driven Development and improved collaboration.

 
 

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page