Cucumber Report Generation

Cucumber provides several ways to generate test execution reports, which are helpful for analyzing test results, sharing with teams, and debugging failures.

Basic Report with pretty Plugin
This prints a detailed text output in the console (in readable format).
@CucumberOptions(
    plugin = {"pretty"}
)

HTML Report
Generate a basic HTML report:

@CucumberOptions(
    plugin = {"pretty", "html:target/cucumber-reports.html"}
)
This creates a report at: target/cucumber-reports.html


JSON Report
Use this when you want to integrate with tools like Extent Reports, Allure, or Jenkins:

@CucumberOptions(
    plugin = {"json:target/cucumber.json"}
)
Output: cucumber.json file that can be parsed by reporting tools.


JUnit XML Report
Useful for CI tools (like Jenkins) to parse test results:

@CucumberOptions(
    plugin = {"junit:target/cucumber-results.xml"}
)


@CucumberOptions(
features = "src/test/java/features",
glue = "stepDefinitions",
plugin = {
"pretty",
"html:target/cucumber-reports.html",
"json:target/cucumber.json",
"junit:target/cucumber-results.xml",
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"
},
monochrome = true,
tags = "@SmokeTest"
)
public class TestNGRunner extends AbstractTestNGCucumberTests {
}




========================= EXAMPLE ===============================

AutomationCucumber/ ├── src/test/java/ │ ├── features/ReportGenerate.feature │ ├── stepDefinitions/RepportGenerationSteps.java │ └── cucumberOptions/TestNGRunnerReport.java └── pom.xml (includes required plugins)


ReportGenerate.feature

Feature: Gmaillogin

@UserGmailLogin

Scenario: Normal flow Gmail-Login

Given user is on Gmaillogin Page

When user login into gmail with "haritaraka" and password "paswrd1234"

Then navigate to gmail homepage

And all maillboxes are displayed

@UserGmailCreate

Scenario Outline: Create a new user for Gmail account

Given user is landing in Gmail user creation page

When user is login with "<Username>" and password "<Password>" combination

Then newuser homepage is displayed

And mailboxes are displayed to the user


Examples:

| Username                 | Password                 |

| prabhumanyam | prabhu76896 |

| subhumanyam         | subhu14868         |



RepportGenerationSteps.java


package stepDefinitions;


import java.util.List;

import java.util.Map;


import io.cucumber.java.en.Given;

import io.cucumber.java.en.Then;

import io.cucumber.java.en.When;


public class RepportGenerationSteps {

@Given("user is on Gmaillogin Page")

public void userisonGmailloginPage() {

System.out.println("Executed user is on Gmaillogin Page");

}


@When("user login into gmail with {string} and password {string}")

public void userloginintogmailwithpassword(String username, String password) {

System.out.println("user login into gmail with " + username + " and password is " +password );

}

@Then("navigate to gmail homepage")

public void navigatetogmailhomepage() {

System.out.println("Executed navigate to gmail homepage ");

}


@Then("all maillboxes are displayed")

public void allmaillboxesaredisplayed() {

System.out.println("Executed Cards are displayed");

System.out.println("=========================================================");

}


//***********************************************************************************//

@Given("user is landing in Gmail user creation page")

public void userislandinginGmailusercreationpage() {

System.out.println("Executed user is landing in Gmail user creation page");

}


@When("user is login with {string} and password {string}")

public void userisloginwith(String string1, String string2) {

System.out.println("user is login with " + string1 + " and password is " +string2 );

}

@Then("newuser homepage is displayed")

public void newuser_homepageisdisplayed() {

System.out.println("Executed newuser homepage is displayed ");

}


@Then("mailboxes are displayed to the user")

public void mailboxesaredisplayedtotheuser() {

System.out.println("Executed mailboxes are displayed to the user");

System.out.println("=========================================================");

}

}




TestNGRunnerReport.java

package cucumberOptions;


import io.cucumber.testng.AbstractTestNGCucumberTests;

import io.cucumber.testng.CucumberOptions;


@CucumberOptions(features = "src/test/java/features", glue = "stepDefinitions", tags = "@UserGmailLogin or @UserGmailCreate",

plugin = {

"pretty",

"html:target/cucumber-reports.html",

"json:target/cucumber.json" }

, monochrome = true)

public class TestNGRunnerReport extends AbstractTestNGCucumberTests {

}



Output:









Without Pretty plugin