October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Generate Extent Reports with Selenium in Java

Generate an ExtentReports Spark HTML file from Java Selenium tests, connect its statuses to real test outcomes, and ensure the report flushes after failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To generate an Extent Report with Selenium, add the ExtentReports Java dependency, attach an ExtentSparkReporter to one ExtentReports instance, create a report entry for each test, log the real test outcome, and call flush() after execution. The example below creates an HTML report at target/Spark.html. This Java workflow is not drop-in code for Python, JavaScript, or C# projects.

1. Add ExtentReports to your Java project

The documented workflow uses the com.aventstack:extentreports artifact and recommends dependency management with Maven or Gradle. Maven Central listed version 5.1.2 at the research timestamp; confirm the current version in Maven Central before implementing the example, since releases can change. Selenium is a separate dependency: Selenium’s official downloads page listed Java 4.49.0, released September 9, 2026. Choose versions compatible with your Java version and test framework; these are independent dependencies, not a paired release.

For Maven, add the ExtentReports dependency to your pom.xml:

<dependency>
  <groupId>com.aventstack</groupId>
  <artifactId>extentreports</artifactId>
  <version>5.1.2</version>
</dependency>

Check Maven Central’s ExtentReports artifact listing for the version available when you build. For Gradle, use the same group, artifact, and verified version in the project’s dependency declaration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Create a Spark HTML report

ExtentReports records test information; it does not perform Selenium actions or replace assertions from JUnit, TestNG, or another test framework. The following compact example illustrates report setup and output only. Its pass() call is intentionally not an assertion: in a real test, report pass only after the actual assertions succeed.

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;

public class ReportExample {
    public static void main(String[] args) {
        ExtentReports extent = new ExtentReports();
        ExtentSparkReporter spark = new ExtentSparkReporter("target/Spark.html");
        extent.attachReporter(spark);

        ExtentTest test = extent.createTest("Home page loads");
        // Run Selenium actions and assertions here; only log pass if they succeed.
        test.pass("Home page loaded successfully");

        extent.flush();
    }
}

Run the project using its normal build or test command, then open target/Spark.html relative to the project directory. Ensure the parent output directory exists if your build setup does not create it.

3. Connect report entries to actual test results

  1. Create a single ExtentReports instance for the test run and attach the Spark reporter to it.
  2. Create an ExtentTest entry for each test, using a stable, recognizable test name.
  3. Run the Selenium test and let the test framework perform its assertions.
  4. Log pass, failure, or skip according to the framework’s actual result. Add concise step notes and relevant exception details so the report helps explain what happened.
  5. Flush the report after execution, including when a test fails. A suite teardown method or the framework’s listener/extension is a typical place to guarantee cleanup, but the precise hook depends on the test framework; there is no single universal TestNG, JUnit, or other lifecycle hook established by the reporting API.

For a useful team artifact, include stable test names, outcomes, relevant failure details, and enough environment or build context to distinguish runs. ExtentReports supports attaching screenshots, but choose and manage screenshot storage paths and retention according to your project; there is no universal capture strategy specified by the documentation.

4. Use the version 5 API, not old tutorials

Use the current com.aventstack group for the documented versions. Older guides may use com.relevantcodes, which belongs to ExtentReports up to version 2. In the version 5 guide, ExtentHtmlReporter and ExtentLoggerReporter are described as deprecated in the 4.1.x series and removed in version 5. For a new HTML report, use ExtentSparkReporter and match all API calls to the library version actually in your build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

See the ExtentReports version 5 Java guide for the reporting API, and the Selenium downloads page for Selenium release information.

5. Troubleshoot common report problems

  • No report file appears: Confirm that execution reaches extent.flush(), that the configured path is the one you are checking, and that the process can write to that location. If tests can fail before teardown, move flushing into a cleanup path that still runs after failure.
  • The report says a test passed when it failed: Do not call test.pass() unconditionally. Connect Extent status logging to the test framework’s actual result and record exception details for failures.
  • Old sample code does not compile: Check the artifact group and library version. Version 5 uses ExtentSparkReporter; examples based on removed reporters or the older com.relevantcodes package need updating.
  • The report is missing useful failure context: Log concise test steps and relevant exception information, and add environment/build context where it helps identify the run. If screenshots are attached, verify their paths and retention rules.
  • A dependency or API mismatch occurs: Verify the resolved ExtentReports version and check that code examples match it. Select compatible Java, Selenium, and test-framework versions rather than assuming the ExtentReports and Selenium versions must match each other.

Or skip the browser setup

ExtentReports is for recording automated test results; it does not take the place of Selenium when your job is to run browser tests. If you also need a rendered-page image or PDF without setting up a browser capture flow, ScreenshotNeo offers a one-request screenshot API. Its clean-capture steps accept cookie and consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers.

For example, this cURL request saves a WebP capture of Stripe. See the ScreenshotNeo API documentation for request options and response details.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo also has an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does ExtentReports execute Selenium tests?

No. It records test information and outcomes; Selenium and your test framework still perform browser actions and assertions.

Can I use this Java example unchanged with Python or JavaScript Selenium?

No. The example uses the Java ExtentReports API and must not be treated as cross-language code.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.