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.