Advanced
Chapter 16 · 11 min read
Reporting — Allure, HTML & Extent
Generate rich test reports with Allure, Cucumber HTML, and Extent Reports. Attach screenshots, logs, and step details.
Test Reporting
Good reports make test results actionable — showing what passed, what failed, why it failed, and evidence (screenshots, logs). Cucumber integrates with several reporting tools out of the box.
ReportingRunner.java
package com.bdd.course.runner;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(
features = "src/test/resources/features",
glue = "com.bdd.course.stepdefinitions",
plugin = {
"pretty",
// Built-in Cucumber HTML report
"html:target/cucumber-reports.html",
// JSON for third-party tools
"json:target/cucumber.json",
// JUnit XML for CI/CD
"junit:target/cucumber-junit.xml",
// Allure (if allure-cucumber7-jvm dependency added)
"io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm",
// Timeline (parallel execution visualization)
"timeline:target/timeline"
}
)
public class ReportingRunner extends AbstractTestNGCucumberTests {}
// pom.xml dependencies:
// <dependency>
// <groupId>io.qameta.allure</groupId>
// <artifactId>allure-cucumber7-jvm</artifactId>
// <version>2.25.0</version>
// <scope>test</scope>
// </dependency>
//
// Run: mvn clean test
// Allure: mvn allure:serve
HooksWithAttach.java
package com.bdd.course.hooks;
import io.cucumber.java.*;
import org.openqa.selenium.*;
public class HooksWithAttach {
@After
public void afterScenario(Scenario scenario) {
WebDriver driver = /* get from context */null;
if (driver != null) {
// Attach screenshot to report
if (scenario.isFailed()) {
byte[] screenshot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png",
"Failure Screenshot");
}
// Attach page source for debugging
scenario.attach(
driver.getPageSource().getBytes(),
"text/html",
"Page Source");
// Attach custom text
scenario.attach(
("URL: " + driver.getCurrentUrl()).getBytes(),
"text/plain",
"Current URL");
driver.quit();
}
// Log scenario result
scenario.log("Status: " + scenario.getStatus());
}
}
allure_reporting.sh
# Behave Allure reporting
# pip install allure-behave
# Run with Allure formatter
behave -f allure_behave.formatter:AllureFormatter -o reports/allure
# Generate and open Allure report
allure serve reports/allure
# JUnit XML reports
behave --junit --junit-directory=reports/junit/
# Built-in pretty output
behave --format=pretty
# JSON output for custom processing
behave --format=json --outfile=reports/results.json
# Multiple formats at once
behave -f pretty -f json -o reports/results.json
environment_reporting.py
# features/environment.py — with reporting attachments
import os, datetime, json
from selenium import webdriver
def after_scenario(context, scenario):
if hasattr(context, 'driver'):
# Screenshot on failure
if scenario.status == "failed":
os.makedirs("reports/screenshots", exist_ok=True)
ts = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
path = f"reports/screenshots/{scenario.name}_{ts}.png"
context.driver.save_screenshot(path)
# Attach to Allure report (if using allure-behave)
import allure
allure.attach.file(path, name="Screenshot",
attachment_type=allure.attachment_type.PNG)
allure.attach(context.driver.current_url,
name="URL", attachment_type=allure.attachment_type.TEXT)
context.driver.quit()
def after_step(context, step):
# Attach screenshot after every step (for detailed reports)
if hasattr(context, 'driver') and step.status == "failed":
import allure
png = context.driver.get_screenshot_as_png()
allure.attach(png, name=f"Step: {step.name}",
attachment_type=allure.attachment_type.PNG)
Cucumber BDD
Advanced
Reporting — Allure, HTML & Extent
Written by PV
© 2026 All Rights Reserved