0
0
Selenium Javatesting~5 mins

Extent Reports setup in Selenium Java

Choose your learning style9 modes available
Introduction

Extent Reports help you create clear and colorful test reports. They show which tests passed or failed in an easy way.

When you want to see a detailed report of your Selenium test results.
When you need to share test results with your team or manager.
When you want to track test progress over time with nice visuals.
When you want to add screenshots or logs to your test reports.
When you want to organize test results by test cases or features.
Syntax
Selenium Java
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("extentReport.html");
ExtentReports extent = new ExtentReports();
extent.attachReporter(htmlReporter);
ExtentTest test = extent.createTest("TestName", "Test Description");
test.pass("Step passed message");
extent.flush();

Use ExtentHtmlReporter to create an HTML report file.

Call extent.flush() at the end to save the report.

Examples
This sets up the report file named report.html.
Selenium Java
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("report.html");
ExtentReports extent = new ExtentReports();
extent.attachReporter(htmlReporter);
This creates a test entry and marks it as passed.
Selenium Java
ExtentTest test = extent.createTest("Login Test", "Tests user login");
test.pass("Login successful");
This marks the test as failed with a message.
Selenium Java
test.fail("Login failed due to invalid credentials");
Sample Program

This program sets up Extent Reports, creates two test cases with pass and fail steps, and saves the report as testReport.html.

Selenium Java
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;

public class ExtentReportSetup {
    public static void main(String[] args) {
        ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("testReport.html");
        ExtentReports extent = new ExtentReports();
        extent.attachReporter(htmlReporter);

        ExtentTest test1 = extent.createTest("Google Search Test", "Test Google search functionality");
        test1.pass("Navigated to Google homepage");
        test1.pass("Entered search text");
        test1.pass("Search results displayed successfully");

        ExtentTest test2 = extent.createTest("Login Test", "Test login with invalid credentials");
        test2.fail("Login failed due to wrong password");

        extent.flush();
        System.out.println("Report generated: testReport.html");
    }
}
OutputSuccess
Important Notes

Always call extent.flush() to write the report file.

Use meaningful test names and descriptions for clarity.

You can add screenshots or logs to tests for better reports.

Summary

Extent Reports create easy-to-read HTML test reports.

Set up with ExtentHtmlReporter and attach to ExtentReports.

Create tests with createTest() and log results with pass() or fail().