Cucumber Reports

  

What are Cucumber Reports?

Cucumber Reports are test execution reports generated after running Cucumber tests (BDD tests written using Gherkin). These reports provide detailed insights into the execution of scenarios, steps, and features — including their status (passed/failed/skipped), duration, and even screenshots (if configured).


Why are Cucumber Reports Useful?

FeatureDescription
Readable FormatProvides human-readable output for business users and stakeholders.
DebuggingHelps in identifying which steps/scenarios failed and why.
TraceabilityYou can trace the execution from the feature file to the actual code.
Data-Driven InsightsUseful for analytics and continuous integration systems.



Types of Reports in Cucumber

Cucumber natively supports multiple report formats:

Report FormatDescription
prettyHuman-readable output in the console
htmlStatic HTML report
jsonStructured data for third-party tools
junitXML format compatible with CI tools like Jenkins
rerunCaptures only failed scenarios for re-execution


How to Generate Reports in Cucumber (Java)

We'll use Maven + Cucumber + TestNG as the base.

Step 1: Add Dependencies in pom.xml


<dependencies>
    <!-- Cucumber dependencies -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>7.15.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>7.15.0</version>
    </dependency>

    <!-- TestNG -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.8.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>




Step 2: Create Feature File (Login.feature)

Feature: Login Feature

  Scenario: Successful login
    Given User is on login page
    When User enters valid username and password
    Then User should be redirected to the homepage




Step 3: Step Definition (LoginSteps.java)

package stepdefinitions;

import io.cucumber.java.en.*;

public class LoginSteps {

    @Given("User is on login page")
    public void user_on_login_page() {
        System.out.println("User on login page");
    }

    @When("User enters valid username and password")
    public void user_enters_credentials() {
        System.out.println("Entered valid credentials");
    }

    @Then("User should be redirected to the homepage")
    public void user_on_homepage() {
        System.out.println("Redirected to homepage");
    }
}




Step 4: Test Runner (TestRunner.java)

package runner;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;

@CucumberOptions(
    features = "src/test/resources/features",
    glue = {"stepdefinitions"},
    plugin = {
        "pretty",
        "html:target/cucumber-reports/report.html",
        "json:target/cucumber-reports/report.json",
        "junit:target/cucumber-reports/report.xml"
    },
    monochrome = true
)
public class TestRunner extends AbstractTestNGCucumberTests {
}



Step 5: Run Tests

  • Run the TestRunner.java as a TestNG Test.

  • Reports will be generated in the target/cucumber-reports/ directory.



Sample Output Report Paths

FormatPath
HTMLtarget/cucumber-reports/report.html
JSONtarget/cucumber-reports/report.json
JUnittarget/cucumber-reports/report.xml




Important points:

  • Cucumber supports multiple report formats like prettyhtmljson, and junit.
  • Reports are configured using the plugin option in @CucumberOptions.
  • Reports help in debugging, analyzing, and integrating with CI tools.

Integration of Extent Report with Cucumber

  

To use Extent Reports in Cucumber for reporting test execution results in a visually appealing and structured format, follow these steps:


What is Extent Report?

Extent Reports is a reporting library that provides a rich HTML-based test execution report. You can integrate it with Cucumber to generate reports that include test status, steps, screenshots, and logs.


Steps to Integrate Extent Reports with Cucumber

1. Add Maven Dependencies

<dependencies>
    <!-- Cucumber dependencies -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>7.14.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>7.14.0</version>
    </dependency>

    <!-- Extent Reports -->
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>5.1.1</version>
    </dependency>

    <!-- Extent Cucumber Adapter -->
    <dependency>
        <groupId>tech.grasshopper</groupId>
        <artifactId>extentreports-cucumber7-adapter</artifactId>
        <version>1.7.0</version>
    </dependency>
</dependencies>




2. Create extent.properties file (in src/test/resources)

extent.reporter.spark.start=true
extent.reporter.spark.out=target/ExtentReports/SparkReport.html
extent.reporter.avent.start=false
extent.reporter.bdd.start=false
extent.reporter.logger.start=false


This configures the Extent Spark Reporter to generate an HTML report in target/ExtentReports/.



3. Create Test Runner Class

package runner;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;

@CucumberOptions(
    features = "src/test/resources/features",
    glue = {"stepdefinitions"},
    plugin = {
        "pretty",
        "html:target/cucumber-html-report.html",
        "json:target/cucumber.json",
        "timeline:test-output-thread/",
        "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"
    },
    monochrome = true
)
public class TestRunner extends AbstractTestNGCucumberTests {
}




4. Sample Step Definition

package stepdefinitions;

import io.cucumber.java.en.Given;

public class LoginSteps {

    @Given("User is on the login page")
    public void user_is_on_the_login_page() {
        System.out.println("User is on login page");
    }

    @Given("User enters valid credentials")
    public void user_enters_valid_credentials() {
        System.out.println("User enters credentials");
    }

    @Given("User is navigated to the home page")
    public void user_is_navigated_to_the_home_page() {
        System.out.println("User navigates to home page");
    }
}




5. Sample Feature File

Create a feature file at src/test/resources/features/login.feature

Feature: Login Feature

  Scenario: Valid Login
    Given User is on the login page
    And User enters valid credentials
    Then User is navigated to the home page




Running the Tests:

Run your test runner class (TestRunner.java) as a TestNG Test. After execution:

A detailed report will be available at:

target/ExtentReports/SparkReport.html



Benefits of Extent Reports

  • Beautiful HTML reports.

  • Easy to customize.

  • Supports screenshots and logs.

  • Works well with parallel execution.

Cucumber Options in Cucumber

  

In Cucumber@CucumberOptions is an important annotation used in the Test Runner class to define and customize the behavior of the Cucumber framework while executing tests. This annotation comes from the io.cucumber.junit or cucumber.api package (depending on the version you're using).


What is @CucumberOptions?

@CucumberOptions is used to configure various execution parameters for running Cucumber tests. It helps define where feature files and step definitions are located, how the results should be reported, and what tags or filters to apply during test execution.


Syntax Example

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "src/test/resources/features",
    glue = "stepdefinitions",
    plugin = {"pretty", "html:target/cucumber-report.html"},
    monochrome = true,
    tags = "@SmokeTest"
)
public class TestRunner {
}




Parameters of @CucumberOptions


ParameterDescription
featuresPath to the .feature files. It can be a directory or specific file path.
gluePackage name(s) where step definitions and hooks are defined.
pluginUsed for report generation. Common plugins include "pretty", "html:target/report.html", "json:target/report.json" etc.
monochromeMakes the console output more readable by removing unnecessary characters. Set to true or false.
tagsFilters which scenarios or features to run based on assigned tags. Useful for running subsets like @SmokeTest, @Regression.
dryRunIf true, it checks if every Step in the feature file has a corresponding Step Definition without executing the tests.
strictIf true, fails execution if there are undefined or pending steps.
nameRuns scenarios whose names match the given regular expression.
snippetsControls the style of generated snippets (CAMELCASE or UNDERSCORE).



Example with Explanation

@CucumberOptions(
    features = "src/test/resources/features/Login.feature", // specific feature file
    glue = "stepdefinitions.login",                          // package with step defs
    plugin = {
        "pretty",
        "json:target/jsonReports/report.json",
        "html:target/htmlReports"
    },
    tags = "@Regression and not @WIP",                       // include/exclude based on tags
    monochrome = true,                                       // clean console output
    dryRun = false,                                          // actually runs the tests
    strict = true                                            // fails on undefined steps
)


When and Where Is It Used?

  • Placed above the Test Runner class that runs with @RunWith(Cucumber.class).

  • Helps control the execution and reporting of Cucumber tests.

  • Allows filtering which scenarios to run in large test suites.

  • Provides integration with tools like Jenkins and Allure via plugins.



Important Points:

@CucumberOptions gives you flexibility and control over how your Cucumber test suite runs by specifying:

  • where your tests are,

  • how they should be reported,

  • which tests to run,

  • and how results should be formatted.

What are Gherkins Keywords in Cucumber

  

Gherkin Keywords in Cucumber

Gherkin is the language used to write Cucumber feature files. It follows a structured syntax using keywords that make it easy for both technical and non-technical stakeholders to understand test scenarios in Behavior-Driven Development (BDD).


What is Gherkin?

  • Gherkin is a domain-specific language (DSL) for writing human-readable tests.

  • Each line in a Gherkin file begins with a keyword, followed by natural language describing the behavior.

  • File extension: .feature




Gherkin Keywords List

KeywordDescription
FeatureDefines the feature or functionality under test.
ScenarioDefines a single concrete example or test case.
Scenario OutlineAllows running the same scenario with different data sets.
ExamplesProvides the data table for Scenario Outline.
GivenDescribes the initial context or preconditions.
WhenDescribes the action or event (trigger).
ThenDescribes the expected outcome or result.
AndUsed to add more conditions to Given, When, or Then.
ButAdds a negative condition to a step.
BackgroundDefines common steps shared by all scenarios in a feature file.
*Wildcard, can replace Given, When, Then, etc., to improve readability.




Example of Gherkin Feature File

Feature: Login functionality

  Background:
    Given the user is on the login page

  Scenario: Successful login
    When the user enters valid credentials
    Then the user should be redirected to the dashboard

  Scenario: Unsuccessful login
    When the user enters invalid credentials
    Then an error message should be displayed




Scenario Outline Example with Examples Table

Scenario Outline: Login with multiple credentials
  Given the user is on the login page
  When the user enters username "<username>" and password "<password>"
  Then the login result should be "<result>"

  Examples:
    | username | password | result         |
    | user1    | pass1    | success        |
    | user2    | wrong    | error message  |




Important Points:

  • Gherkin supports multiple languages (like French, Hindi, etc.).

  • Keywords must be followed by plain language sentences.

  • Each scenario is independent (except for Background steps).

Parameterization in Cucumber

  

What is Parameterization in Cucumber?

Parameterization in Cucumber allows you to pass different input data into your Gherkin steps (feature files), enabling reusability of steps and data-driven testing. Instead of writing separate scenarios for each data input, you can parameterize the steps using:

  1. Regular Expressions (Step Definition Parameters)

  2. Scenario Outline and Examples Table



1. Parameterization using Step Definition Parameters

You can define steps with placeholders using double quotes (") and capture them in the step definitions with regex or Cucumber expressions.


Feature File (Login.feature)

Feature: Login Feature

  Scenario: Login with valid credentials
    Given User logs in with username "john" and password "password123"




Step Definition in Java

import io.cucumber.java.en.Given;

public class LoginSteps {

    @Given("User logs in with username {string} and password {string}")
    public void user_logs_in_with_credentials(String username, String password) {
        System.out.println("Username: " + username);
        System.out.println("Password: " + password);
        // Add login logic here
    }
}



2. Parameterization using Scenario Outline and Examples Table

This is useful when you want to run the same scenario multiple times with different inputs.


Feature File with Scenario Outline (Login.feature)

Feature: Login Feature

  Scenario Outline: Login with multiple credentials
    Given User logs in with username "<username>" and password "<password>"

    Examples:
      | username | password     |
      | john     | password123  |
      | alice    | qwerty456    |
      | bob      | 12345        |





Step Definition in Java

import io.cucumber.java.en.Given;

public class LoginSteps {

    @Given("User logs in with username {string} and password {string}")
    public void user_logs_in_with_credentials(String username, String password) {
        System.out.println("Username: " + username);
        System.out.println("Password: " + password);
        // Add logic to perform login here
    }
}




Important Points

FeatureBenefit
Step ParameterizationReusable steps with dynamic data
Scenario Outline + ExamplesData-driven testing made easy
Reduces code duplicationLess maintenance, more clarity

Data Driven Testing using Cucumber

  

What is Data-Driven Testing in Cucumber Using Examples Keyword?

Data-Driven Testing in Cucumber is a method that allows you to run the same scenario multiple times with different sets of data. This is done using the Scenario Outline and Examples keywords in the Gherkin language.


Why Use Data-Driven Testing?

  • Eliminates code duplication

  • Increases test coverage

  • Allows testing edge cases easily

  • Makes test scenarios readable and maintainable


 Gherkin Keywords Used

KeywordDescription
Scenario OutlineUsed when you want to run the same scenario with multiple data sets
ExamplesContains the table of input values that will be injected into the scenario


Syntax Example

Feature File: login.feature

Feature: Login Feature

  Scenario Outline: Valid login with multiple credentials
    Given User is on the login page
    When User enters username "<username>" and password "<password>"
    Then User should see the dashboard

    Examples:
      | username | password  |
      | user1    | pass123   |
      | user2    | password1 |
      | admin    | admin123  |

 

Step Definition in Java

File: LoginSteps.java

package stepDefinitions;

import io.cucumber.java.en.*;

public class LoginSteps {

    @Given("User is on the login page")
    public void user_is_on_the_login_page() {
        System.out.println("User navigates to login page");
    }

    @When("User enters username {string} and password {string}")
    public void user_enters_username_and_password(String username, String password) {
        System.out.println("Entered Username: " + username);
        System.out.println("Entered Password: " + password);
    }

    @Then("User should see the dashboard")
    public void user_should_see_the_dashboard() {
        System.out.println("User lands on the dashboard");
    }
}




Test Runner Class

package testRunner;

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "src/test/resources/features",
    glue = {"stepDefinitions"},
    plugin = {"pretty", "html:target/cucumber-reports.html"},
    monochrome = true
)
public class TestRunner {
}



Project Structure

src/
 └── test/
     └── java/
         └── stepDefinitions/
             └── LoginSteps.java
         └── testRunner/
             └── TestRunner.java
     └── resources/
         └── features/
             └── login.feature



Output

User navigates to login page
Entered Username: user1
Entered Password: pass123
User lands on the dashboard

User navigates to login page
Entered Username: user2
Entered Password: password1
User lands on the dashboard

User navigates to login page
Entered Username: admin
Entered Password: admin123
User lands on the dashboard




Important Points:


FeatureDescription
Data-Driven TestingRun one scenario with multiple data sets
Scenario OutlineDefines a scenario template
ExamplesData table used for substitution in the scenario
BenefitAvoids duplication, increases maintainability and test coverage