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.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
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.
Rank #2
3. Connect report entries to actual test results
- Create a single
ExtentReportsinstance for the test run and attach the Spark reporter to it. - Create an
ExtentTestentry for each test, using a stable, recognizable test name. - Run the Selenium test and let the test framework perform its assertions.
- 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.
- 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.
Recommended Free Tools
Rank #3
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 oldercom.relevantcodespackage 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.
Rank #4
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.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteFrequently 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.
Best Value
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.
Quick Recap
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.




