Extent Reports in Selenium is a reporting library that provides detailed, interactive test execution results. It allows testers to capture test outcomes with logs, screenshots, and structured visualizations, making it easier to analyze failures and successes.
Unlike simple console outputs or basic reports, Extent Reports offers hierarchical test structures, real-time updates, and multiple formats such as HTML. This enables teams to track automation results efficiently and consistently.
This article explains the setup, configuration, and usage of Extent Reports in Selenium, along with advanced practices like capturing screenshots, logging details, and troubleshooting common issues.
Extent Report in Selenium is a framework-independent library designed to generate interactive and comprehensive test execution reports. The reports include detailed logs, step-wise execution results, timestamps, system information, and visual elements like charts and screenshots.
The key advantage of Extent Reports is that it organizes test information hierarchically. Tests can be grouped into suites, and each test can have multiple steps with individual statuses. This makes it easier for teams to track, analyze, and debug test failures in large automation projects.
Below are the core aspects that define Extent Reports and its value in Selenium testing:
Extent Reports offers several features that make it a preferred choice for reporting in Selenium automation projects. These features go beyond simple pass/fail results and provide actionable insights for testers and development teams. Understanding these features helps in leveraging the full potential of Extent Reports. Below are the key features explained in detail:
Setting up Extent Reports in Selenium involves adding the required libraries, initializing the reporting objects, and configuring the output location and format. Proper setup ensures that reports capture test execution details accurately and are easy to analyze. Below is a step-by-step explanation of how to install and configure Extent Reports.
Extent Reports can be added to a project either via Maven or by manually downloading the JAR files. Using Maven is recommended for easier version management.
For a Maven project, include the following dependency in your pom.xml:
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>
For projects not using Maven, download the JAR from the Extent Reports official repository and add it to your project’s build path.
Once the dependency is added, you need to create an instance of ExtentReports and configure the report output location.
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
public class ExtentReportSetup {
public static void main(String[] args) {
// Specify the location of the report
ExtentSparkReporter spark = new ExtentSparkReporter("test-output/ExtentReport.html");
// Create ExtentReports instance
ExtentReports extent = new ExtentReports();
// Attach reporter
extent.attachReporter(spark);
// Create a test entry
ExtentTest test = extent.createTest("Login Test")
.assignAuthor("QA Team")
.assignCategory("Functional Test");
// Log steps
test.pass("Navigated to login page");
test.pass("Entered valid credentials");
test.fail("Dashboard did not load");
// Generate the report
extent.flush();
}
}
The ExtentSparkReporter allows customization of the report appearance:
spark.config().setDocumentTitle("Automation Test Report");
spark.config().setReportName("Regression Suite");
spark.config().setTheme(com.aventstack.extentreports.reporter.configuration.Theme.STANDARD);
You can generate multiple reports in a single project by creating different instances of ExtentSparkReporter and attaching them to a single ExtentReports object. This is useful for separating test reports by module, environment, or execution cycle.
It is recommended to store reports in a dedicated folder, such as test-output, to keep them organized. Reports can be automatically overwritten or versioned using timestamps:
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
ExtentSparkReporter spark = new ExtentSparkReporter("test-output/ExtentReport_" + timeStamp + ".html");
This ensures that each test execution generates a unique report without overwriting previous results.
Generating Extent Reports in Selenium involves creating tests, logging steps, and producing the final report file. This process allows testers to capture detailed execution results with status indicators, screenshots, and additional context.
Below is a step-by-step explanation of how to generate Extent Reports effectively.
Before logging any test steps, initialize the ExtentReports and ExtentSparkReporter objects. Specify the report file location and attach the reporter:
ExtentSparkReporter spark = new ExtentSparkReporter("test-output/ExtentReport.html");
ExtentReports extent = new ExtentReports();
extent.attachReporter(spark);
Each test in your automation suite should have an associated ExtentTest object. This object is used to log individual steps:
ExtentTest loginTest = extent.createTest("Login Test")
.assignAuthor("QA Team")
.assignCategory("Functional Test");
Log each step of the test with appropriate status levels. Statuses can include pass, fail, skip, or warning. Additional details such as execution messages or exceptions can also be added:
loginTest.pass("Navigated to login page");
loginTest.pass("Entered username and password");
loginTest.fail("Login button not clickable due to overlay");
loginTest.warning("Dashboard load time exceeded threshold");
Screenshots provide visual evidence for test failures or critical steps. Capture screenshots using Selenium and attach them to the report:
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
File destination = new File("screenshots/loginFail.png");
FileUtils.copyFile(source, destination);
loginTest.addScreenCaptureFromPath("screenshots/loginFail.png");
After all tests and steps are logged, generate the report by calling flush() on the ExtentReports object. This writes all logs, screenshots, and structured information to the output file:
extent.flush();
For suites with multiple test cases, create separate ExtentTest objects for each test and log steps independently. This allows the report to display each test case clearly with hierarchical details:
ExtentTest searchTest = extent.createTest("Search Test");
searchTest.pass("Navigated to search page");
searchTest.pass("Entered search keyword");
searchTest.fail("Search results did not load");
By following these steps, testers can generate detailed Extent Reports that provide clear insights into test execution, step-by-step status, and issues encountered. These reports help teams identify failures quickly and maintain historical test execution records.
TestNG is one of the most popular frameworks for Selenium automation, and Extent Reports integrates seamlessly with it. Using Extent Reports with TestNG allows testers to capture results for each test method, log steps, and generate structured HTML reports automatically after execution. Below is a detailed guide on how to implement it.
Ensure both TestNG and Extent Reports dependencies are included in your pom.xml:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>
Using a TestNG listener ensures that reports are generated automatically for all test methods.
Create a class implementing ITestListener:
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
public class ExtentTestNGListener implements ITestListener {
ExtentReports extent;
ExtentTest test;
@Override
public void onStart(ITestContext context) {
ExtentSparkReporter spark = new ExtentSparkReporter("test-output/ExtentReport.html");
extent = new ExtentReports();
extent.attachReporter(spark);
}
@Override
public void onTestStart(ITestResult result) {
test = extent.createTest(result.getMethod().getMethodName());
}
@Override
public void onTestSuccess(ITestResult result) {
test.pass("Test Passed");
}
@Override
public void onTestFailure(ITestResult result) {
test.fail(result.getThrowable());
}
@Override
public void onTestSkipped(ITestResult result) {
test.skip("Test Skipped");
}
@Override
public void onFinish(ITestContext context) {
extent.flush();
}
}
Apply standard TestNG annotations for your Selenium tests. The listener automatically logs test start, success, failure, or skip events:
import org.testng.annotations.Test;
import org.testng.annotations.Listeners;
@Listeners(ExtentTestNGListener.class)
public class LoginTest {
@Test
public void validLoginTest() {
// Selenium steps to perform login
System.out.println("Login steps executed");
}
@Test
public void invalidLoginTest() {
// Selenium steps that intentionally fail
throw new RuntimeException("Invalid login credentials");
}
}
JUnit is another widely used framework for Selenium automation. Integrating Extent Reports with JUnit allows testers to capture structured test results, log steps, and generate interactive HTML reports for analysis. The process requires initializing Extent Reports in a setup method and flushing the report after all tests execute.
Include both JUnit and Extent Reports dependencies in your pom.xml:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>
Use the @BeforeClass or @Before annotation to initialize the report before executing tests:
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import org.junit.BeforeClass;
import org.junit.AfterClass;
public class JUnitExtentReportTest {
static ExtentReports extent;
static ExtentTest test;
@BeforeClass
public static void setup() {
ExtentSparkReporter spark = new ExtentSparkReporter("test-output/ExtentReport.html");
extent = new ExtentReports();
extent.attachReporter(spark);
}
@AfterClass
public static void tearDown() {
extent.flush();
}
}
Within JUnit test methods, create ExtentTest objects for each test case and log steps with statuses:
import org.junit.Test;
public class LoginTests extends JUnitExtentReportTest {
@Test
public void validLoginTest() {
test = extent.createTest("Valid Login Test");
test.pass("Navigated to login page");
test.pass("Entered valid credentials");
test.pass("Dashboard loaded successfully");
}
@Test
public void invalidLoginTest() {
test = extent.createTest("Invalid Login Test");
test.pass("Navigated to login page");
test.fail("Login failed due to incorrect credentials");
}
}
Screenshots can be captured for failed tests and added to reports for detailed analysis:
// Selenium screenshot capture
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
File destination = new File("screenshots/invalidLogin.png");
FileUtils.copyFile(source, destination);
test.addScreenCaptureFromPath("screenshots/invalidLogin.png");
NUnit is a popular testing framework for .NET applications. Integrating Extent Reports with NUnit allows testers to capture structured test results, log execution steps, and generate interactive HTML reports that provide insights into test outcomes. Below is a detailed guide on how to implement Extent Reports in NUnit.
Include the Extent Reports NuGet package in your .NET project. In Visual Studio, you can run:
Install-Package AventStack.ExtentReports
Ensure NUnit is also installed:
Install-Package NUnit
Install-Package NUnit3TestAdapter
Use [OneTimeSetUp] or [SetUp] attributes to initialize the report before executing tests:
using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using NUnit.Framework;
[TestFixture]
public class NUnitExtentReportTest
{
private static ExtentReports extent;
private ExtentTest test;
[OneTimeSetUp]
public void Setup()
{
var spark = new ExtentSparkReporter("TestResults/ExtentReport.html");
extent = new ExtentReports();
extent.AttachReporter(spark);
}
[OneTimeTearDown]
public void TearDown()
{
extent.Flush();
}
}
Within NUnit test methods, create ExtentTest objects for each test case and log execution details:
[Test]
public void ValidLoginTest()
{
test = extent.CreateTest("Valid Login Test");
test.Pass("Navigated to login page");
test.Pass("Entered valid credentials");
test.Pass("Dashboard loaded successfully");
}
[Test]
public void InvalidLoginTest()
{
test = extent.CreateTest("Invalid Login Test");
test.Pass("Navigated to login page");
test.Fail("Login failed due to incorrect credentials");
}
Screenshots can be captured using Selenium WebDriver for .NET and attached to failed steps:
ITakesScreenshot ts = driver as ITakesScreenshot;
Screenshot screenshot = ts.GetScreenshot();
screenshot.SaveAsFile("Screenshots/InvalidLogin.png", ScreenshotImageFormat.Png);
test.AddScreenCaptureFromPath("Screenshots/InvalidLogin.png");
Capturing screenshots and logging test steps in Extent Reports adds significant value to test automation. It helps testers quickly identify issues, provides visual evidence for failures, and maintains a detailed execution history.
Below is a detailed explanation of how to implement both effectively.
Logging is essential for tracking the progress and outcome of each test step. Extent Reports supports multiple log levels such as pass, fail, skip, and warning.
Example in Java with Selenium:
ExtentTest test = extent.createTest("Login Test");
test.pass("Navigated to login page");
test.pass("Entered valid username and password");
test.fail("Login failed due to incorrect credentials");
test.warning("Dashboard load time exceeded expected threshold");
Screenshots provide visual context for failures or critical actions. Selenium WebDriver supports capturing screenshots using TakesScreenshot.
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
File destination = new File("screenshots/loginFail.png");
FileUtils.copyFile(source, destination);
// Attach screenshot to Extent Report
test.addScreenCaptureFromPath("screenshots/loginFail.png");
For failed steps, combining descriptive logs with screenshots improves clarity and speeds up debugging:
try {
driver.findElement(By.id("loginButton")).click();
test.pass("Clicked login button successfully");
} catch (Exception e) {
test.fail("Failed to click login button: " + e.getMessage());
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("screenshots/loginButtonFail.png"));
test.addScreenCaptureFromPath("screenshots/loginButtonFail.png");
}
You can include system info, environment details, or custom messages to provide context for test execution:
extent.setSystemInfo("OS", "Windows 11");
extent.setSystemInfo("Browser", "Chrome 139");
test.info("Executing login test for production environment");
Capturing both screenshots and detailed logs ensures that Extent Reports serve as a complete record of test execution. It allows testers to quickly identify failure points, reproduce issues, and maintain accountability across test cycles.
Following best practices ensures that Extent Reports provide accurate, detailed, and actionable insights for automation testing. Proper implementation improves readability, consistency, and maintainability of test reports.
Below are the key practices to follow:
Extent Reports in Selenium provides clear, structured, and interactive test execution results. It captures logs, screenshots, and system information, allowing testers to analyze failures and successes effectively. Its integration with frameworks like TestNG, JUnit, and NUnit ensures flexibility across project setups.
To get more reliable results, run Selenium tests on 3,500+ real devices and browsers with BrowserStack. It accelerates test cycles while expanding coverage, and provides video recordings, screenshots, and network logs for easy debugging.
Run Selenium Tests on Cloud
Get visual proof, steps to reproduce and technical logs with one click
Continue reading
Try Bird on your next bug - you’ll love it
“Game changer”
Julie, Head of QA
Try Bird later, from your desktop