📣 Requestly API Client – Free Forever & Open Source. A powerful alternative to Postman. Try now ->

How to Generate Extent Report in Selenium Across Frameworks

Rohit Rajpal
Learn how to generate Extent Reports in Selenium to capture test status, logs, and screenshots across TestNG, JUnit, and NUnit frameworks.
How to Generate Extent Report in Selenium Across Frameworks

Test automation often succeeds in executing Selenium scripts, but reporting test outcomes clearly remains a challenge. Default console logs or basic reports lack context on failures, execution trends, or step-level details, making debugging and analysis slow and error-prone.

Extent Reports in Selenium solve this problem by providing rich, interactive HTML reports with detailed logs, screenshots, and environment information. They help testers and stakeholders quickly understand results, track failures, and take informed action.

This article explains how to generate Extent Reports in Selenium across frameworks including TestNG, JUnit, and NUnit

Understanding Extent Reports in Selenium

Automation tests generate large amounts of data during execution, but raw logs and console outputs are difficult to interpret, especially in complex projects with multiple test cases and parallel execution. Extent Reports provide a structured and visually rich way to present this data.

At its core, an Extent Report is an HTML report that captures detailed information for each test, including test status, execution time, logs, and optional screenshots. It goes beyond simple pass/fail results by allowing hierarchical reporting, so each test case can have multiple steps logged individually. This helps teams identify exactly where a test failed, the sequence of actions leading to it, and the context of the failure.

Below are the key aspects that make Extent Reports a preferred choice for Selenium reporting:

  • Detailed Logs: Records each step of a test with information on success, failure, or warnings. For example, instead of just marking a login test as failed, it logs which element was not found or which assertion failed.
  • Screenshot Integration: Captures screenshots at failure points to provide visual context. This reduces time spent reproducing issues.
  • Environment Information: Reports can include details such as browser, OS, and build version, which is critical for debugging cross-platform issues.
  • Hierarchical Structure: Allows grouping of tests, test suites, and individual steps for clearer navigation and analysis.
  • Interactive and Filterable Reports: Users can filter by status, expand or collapse details, and navigate large test suites efficiently.

Why Use Extent Reports for Test Reporting

Basic Selenium reports and console logs often fail to provide clear insights into test failures or execution trends. This makes debugging slow and communicating results difficult.

Extent Reports address these challenges by offering structured, detailed, and actionable reporting. Here is why they are widely used in Selenium testing:

  • Clear Failure Analysis: Each test step is logged with detailed information, including errors, exceptions, and the exact point of failure. This allows testers to quickly identify root causes.
  • Visual Representation: Reports include charts, graphs, and status indicators, which make it easier to track trends over time and identify recurring issues.
  • Step-Level Logging: Test steps can be logged individually, showing exactly what actions were performed, which assertions passed or failed, and in what order.
  • Enhanced Collaboration: Developers, testers, and managers can view the same report, improving communication and reducing misinterpretation of results.
  • Customizable Reporting: Teams can add relevant metadata, such as test environment, browser versions, or execution times, tailoring the report to project needs.

Setting Up Extent Reports in Selenium

Before generating detailed reports, Extent Reports must be integrated into your Selenium project. The setup process involves adding the necessary dependencies, initializing the reporting object, and configuring output paths. Proper setup ensures that reports capture test execution accurately and consistently across different runs and environments.

Below are the key steps to set up Extent Reports in Selenium:

  1. Add Dependencies: Include the Extent Reports library in your project. For Maven projects, add the relevant dependency in the pom.xml. For Gradle or standalone projects, include the JAR files in the build path.
  2. Initialize Extent Reports: Create an instance of ExtentReports in your test base or setup class. This instance will manage report generation for all test cases.
  3. Configure Output Path: Specify where the HTML report should be generated. A dedicated folder, such as reports/ExtentReport.html, ensures consistent storage and easy access.
  4. Attach Reporter: Use an ExtentHtmlReporter to define the report format, theme, and other display settings. Linking this reporter to the ExtentReports instance enables the HTML output.
  5. Add System Information: Optionally, configure metadata such as OS, browser, environment, and tester name to provide context in the report header.
  6. Flush Reports: At the end of the test suite, call the flush() method to write all logged information to the HTML file. Failing to flush the report can result in incomplete or empty reports.

How to Generate Extent Reports in Selenium: Step by Step

Generating an Extent Report involves initializing the reporting framework, logging test steps, handling failures, and producing the final HTML output. A structured approach ensures that reports are clear, actionable, and consistent across multiple test runs.

Below is a practical step-by-step guide to generating Extent Reports in Selenium:

1. Initialize ExtentReports and ExtentHtmlReporter

Start by creating an instance of ExtentReports and attach an ExtentHtmlReporter. This sets the output location and allows customization of report appearance. For example, you can set the report theme, document title, and encoding.

2. Create Test Cases in the Report

For each test method, create an ExtentTest object. This object represents a single test case in the report and allows logging of multiple steps, statuses, and exceptions.

3. Log Test Steps

Use methods like log(Status.INFO, “Step description”) or pass(), fail(), warning() to record execution details for each step. Logging at a granular level helps pinpoint failures and understand test flow.

4. Capture Screenshots

For failures or checkpoints, capture screenshots using Selenium’s TakesScreenshot interface and attach them to the test report. When running tests across multiple browsers or devices, such as on BrowserStack, these screenshots reflect real user environments and make debugging more accurate and meaningful.

5. Handle Exceptions

Wrap critical test steps in try-catch blocks. On catching an exception, log it using test.fail() and attach the screenshot. Executing tests on cloud platforms or real devices ensures that any environment-specific issues are captured directly in the Extent Report and provides reliable insights across different configurations.

6. Flush the Report

After completing all tests, call extent.flush() to write all logs, screenshots, and metadata to the HTML file. Without this step, the report may remain incomplete or empty.

7. Review the Report

Open the generated HTML file in a browser. You can filter tests by status, expand individual steps, view screenshots, and examine system information for context.

Using Extent Reports with TestNG

TestNG is one of the most widely used testing frameworks with Selenium, offering features like annotations, parallel execution, and grouping. Integrating Extent Reports with TestNG enhances test reporting by providing detailed insights at both the suite and test level.

The process involves initializing the report in a base class, creating tests in each test method, and flushing the report after execution. Below is the recommended approach:

  • Initialize in Base Class: Create ExtentReports and ExtentHtmlReporter objects in a @BeforeSuite method. This ensures the report is initialized once per test suite.
  • Create Test Instances: For each @Test method, create an ExtentTest instance. Log steps using test.log(Status.INFO, “Step description”), marking success or failure as required.
  • Handle Failures with Listeners: Implement TestNG’s ITestListener interface to automatically capture failures and attach screenshots. This ensures any test that fails in parallel or sequential execution is properly logged.
  • Parallel Execution Support: When running tests in parallel, use thread-safe ExtentTest instances, typically stored in a ThreadLocal variable. This prevents overlapping logs and ensures accurate reporting per thread.
  • Flush After Suite: Use @AfterSuite to call extent.flush(), generating the final HTML report once all tests have completed.

Using Extent Reports with JUnit

JUnit is a widely adopted framework for Selenium testing, especially for smaller projects or unit-level automation. Integrating Extent Reports with JUnit provides structured, detailed reports that go beyond JUnit’s basic console output.

To implement Extent Reports with JUnit, follow these steps:

  • Initialize Reports in @BeforeClass or @BeforeAll: Set up ExtentReports and ExtentHtmlReporter before any tests run. This ensures the report is ready for all test methods.
  • Create Test Instances for Each Method: For every @Test method, create an ExtentTest instance and log test steps using log(), pass(), or fail() methods. This gives visibility into each step of execution.
  • Capture Failures Using @Rule or Try-Catch Blocks: JUnit does not have built-in listeners like TestNG, so handle failures either with a try-catch inside each test or by creating a custom TestWatcher rule to log exceptions and attach screenshots automatically.
  • Log Screenshots and Metadata: Capture screenshots for failures and add environment details like browser or OS to provide context. This is particularly useful when tests run on different environments.
  • Flush Reports in @AfterClass or @AfterAll: Call extent.flush() after all tests have executed to generate the final report.

Using Extent Reports with NUnit

NUnit is a popular testing framework for Selenium projects using C# and .NET. Integrating Extent Reports with NUnit allows teams to produce detailed HTML reports that capture execution flow, failures, and screenshots, which are otherwise limited in default NUnit reports.

To implement Extent Reports with NUnit, follow these steps:

  • Initialize Reports in [OneTimeSetUp]: Set up ExtentReports and ExtentHtmlReporter before any tests run. This ensures a single report instance for the entire test suite.
  • Create Test Instances in [SetUp]: For each test method, create an ExtentTest object. Log steps using Log(Status.Info, “Step description”) or Pass() and Fail() to capture results.
  • Capture Failures with Try-Catch: Wrap critical steps in try-catch blocks. On failure, log the exception and attach a screenshot to provide context. NUnit does not provide built-in listeners, so explicit handling is required.
  • Add Environment Information: Include details such as OS, browser version, and tester name in the report for clarity when tests are run across different configurations.
  • Flush Reports in [OneTimeTearDown]: Call extent.Flush() after all tests have executed to generate the HTML report.

Adding Screenshots and Logs to Extent Reports in Selenium

Capturing screenshots and detailed logs is essential for understanding why a test passed or failed. Without them, reports may indicate failures but provide little actionable information. Adding screenshots and logs makes debugging faster and ensures that stakeholders can see exactly what happened during test execution.

Below are practical ways to enhance Extent Reports with screenshots and logs:

  • Log Test Steps: Use test.log(Status.INFO, “Step description”) to record each significant action. Logging at each step provides a chronological view of test execution, making it easier to trace failures.
  • Attach Screenshots on Failures: Capture screenshots using Selenium’s TakesScreenshot interface and attach them using test.addScreenCaptureFromPath(). This provides visual confirmation of issues, reducing the time spent reproducing bugs.
  • Conditional Logging: Log messages based on outcomes, for example using pass(), fail(), or warning(). This differentiates between successful steps, failed steps, and non-critical warnings.
  • Combine Logs and Screenshots: For a failed step, log the error message and attach a screenshot together. This ensures that each failure is fully documented in one place.
  • Capture Screenshots for Checkpoints: Screenshots are not just for failures. Capturing important checkpoints or milestones helps in verifying that the application behaves as expected throughout the test.

Customizing Extent Reports for Better Insights

Out-of-the-box Extent Reports provide a solid foundation, but customizing them can make reports more actionable and aligned with project requirements. Customization helps highlight critical information, improve readability, and provide additional context for test execution.

Here are ways to customize Extent Reports effectively:

  • Themes and Layout: Change the report theme to DARK or STANDARD and configure the document title, report name, and chart location. This improves readability and aligns the report visually with project standards.
  • System Information: Add metadata such as OS, browser version, environment, and tester name using setSystemInfo(). This provides context when reviewing reports across multiple configurations.
  • Categorization of Tests: Assign categories, groups, or tags to tests using assignCategory(). This allows filtering and helps identify tests by feature, priority, or module.
  • Custom Logs and Markers: Use labels, markers, or color-coded logs to emphasize critical steps, warnings, or important checkpoints. This makes reports easier to scan and interpret quickly.
  • Interactive Charts: Configure charts and dashboards in the report to visualize pass/fail ratios, execution trends, and module-level performance. Visual insights make it easier to spot recurring issues or patterns.
  • Screen Capture Annotations: When attaching screenshots, include descriptions or highlights to indicate what part of the application is being shown. This improves clarity, especially for non-technical stakeholders.

Conclusion

Extent Reports provide a structured and interactive way to capture Selenium test results, offering step-level logs, screenshots, and environment details. They go beyond basic pass/fail reporting by delivering actionable insights that help testers and stakeholders identify issues, trace failures, and understand test execution trends.

Integrating Extent Reports with real-device and cross-browser testing on platforms like BrowserStack ensures that reports reflect actual user environments. Tests run across multiple browsers, operating systems, and devices capture environment-specific issues, while screenshots and logs from these runs feed directly into the report.

Written by
Rohit Rajpal
Rohit Rajpal is a B2B Content Strategist at BrowserStack, helping SaaS brands build AI-first strategies that drive authority and revenue. He writes about content, strategy, and the future of search in the zero-click era.

Related posts