Generating Extent Reports in Selenium Java

Extent Reports is a powerful and flexible reporting library for Selenium test automation in Java. It helps you generate detailed, interactive, and visually rich HTML reports for your test execution. These reports show test steps, statuses (pass/fail/skip), screenshots, logs, and other useful test data.

Here’s a simple guide to generating Extent Reports in Selenium Java.

Step 1: Add Dependencies

If you’re using Maven, add the following dependencies to your pom.xml:

<dependencies>

    <!-- Extent Reports -->

    <dependency>

        <groupId>com.aventstack</groupId>

        <artifactId>extentreports</artifactId>

        <version>5.0.9</version>

    </dependency>

</dependencies>

For non-Maven projects, download the .jar files from the official Extent Reports site and add them to your project’s build path.

Step 2: Create and Configure Extent Reports

In your Selenium test project, you can create a separate utility class for setting up Extent Reports.

import com.aventstack.extentreports.ExtentReports;

import com.aventstack.extentreports.ExtentTest;

import com.aventstack.extentreports.reporter.ExtentSparkReporter;

public class ExtentReportManager {

    static ExtentReports extent;

    static ExtentTest test;

    public static ExtentReports getReportObject() {

        String path = System.getProperty("user.dir") + "/reports/index.html";

        ExtentSparkReporter reporter = new ExtentSparkReporter(path);

        reporter.config().setReportName("Automation Test Results");

        reporter.config().setDocumentTitle("Test Report");

        extent = new ExtentReports();

        extent.attachReporter(reporter);

        extent.setSystemInfo("Tester", "Your Name");

        return extent;

    }

}

Step 3: Using Extent Reports in Your Test

Here's how to integrate it in a test class:

import com.aventstack.extentreports.ExtentReports;

import com.aventstack.extentreports.ExtentTest;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Test;

public class SampleTest {

    ExtentReports extent = ExtentReportManager.getReportObject();

    ExtentTest test;

    @BeforeTest

    public void setup() {

        test = extent.createTest("Sample Selenium Test");

    }

    @Test

    public void testExample() {

        test.info("Launching test...");

        test.pass("Test passed successfully.");

    }

    @AfterTest

    public void tearDown() {

        extent.flush(); // writes everything to the report

    }

}

Step 4: Viewing the Report

After test execution, go to the /reports/index.html file in your project directory and open it in a browser to view your test report.

Conclusion

Integrating Extent Reports in your Selenium Java framework enhances the visibility and traceability of your tests. It helps testers, developers, and stakeholders understand test results with visual clarity and logs. You can even add screenshots, custom messages, and categorize tests using Extent Reports for advanced reporting. 

Learn Selenium Java Training in Hyderabad

Read More:

Working with Web Tables in Selenium

Handling Multiple Windows and Tabs

Automating E-commerce Website Checkout Flows

Java Basics Every Selenium Tester Should Know

Integrating Selenium with Jenkins for CI/CD

Visit our IHub Talent Training Institute

Get Direction

Comments

Popular posts from this blog

Tosca Installation and Environment Setup

Automated Regression Testing with Selenium

How Playwright Supports Multiple Browsers