Selenium Reports

A test report turns raw pass and fail results into a story that managers, developers, and testers can read in a minute. Console text vanishes after the run, and long logs bury the facts. A report works like a school report card. It lists every subject, the marks, and a short note on what needs attention. Good reports save hours of guessing after a failed build.

What a Good Report Shows

ItemReason
Total, passed, failed, skipped countsQuick health check
Test name and descriptionIdentifies the checked feature
Failure message and stack tracePoints to the cause
Screenshot at failureShows what the page looked like
Run time and environmentExplains slow runs and browser differences

Report Pipeline

Test Run --> Listener catches events --> Report library writes data
                                                |
                                                v
                                      HTML file: report.html
                                                |
                                                v
                              Team opens the file in any browser

Built-in TestNG Report

TestNG creates a folder called test-output after every run. It holds index.html and emailable-report.html. The files need no setup and work well for early projects. The design stays plain, with limited charts and no screenshots.

ExtentReports

ExtentReports produces a polished page with charts, filters, timelines, and attached images. Most Selenium teams choose it for daily work. Add the library to the project, create a reporter, and log steps inside each test.

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

ExtentSparkReporter spark = new ExtentSparkReporter("reports/result.html");
spark.config().setReportName("Login Tests");
ExtentReports extent = new ExtentReports();
extent.attachReporter(spark);

ExtentTest test = extent.createTest("Valid login");
test.info("Opened login page");
test.pass("Welcome message displayed");
extent.flush();

The flush() call writes everything to disk. Without it, the file stays empty.

Connecting Reports to TestNG

A TestNG listener reacts to each test result automatically. You avoid writing report code inside every test.

public class ReportListener implements ITestListener {
    @Override
    public void onTestSuccess(ITestResult result) {
        test.pass(result.getName() + " passed");
    }
    @Override
    public void onTestFailure(ITestResult result) {
        test.fail(result.getThrowable());
    }
}
Test fails --> TestNG calls onTestFailure --> listener logs error + screenshot

Adding Screenshots to Failures

A picture explains a failure faster than a paragraph. Capture the screen inside onTestFailure, save the file, and attach it to the report entry. Reviewers see the exact page state: an error banner, a missing button, or a blank screen.

Allure as an Alternative

Allure builds a dashboard with graphs, categories, history trends, and step trees. It suits large teams that track quality over many weeks. Extent suits smaller projects with quick setup.

ToolStrengthSetup Effort
TestNG defaultZero setupNone
ExtentReportsFriendly visualsLow
AllureTrends and historyMedium

Habits for Useful Reports

  • Name tests in plain words, such as "Valid user logs in".
  • Log business steps, not every technical line.
  • Store reports with a date and build number in the folder name.
  • Publish the latest report to a shared location.
  • Remove old reports after a set period to save disk space.

Key Points

  • Reports translate test output into readable evidence.
  • Listeners keep report code out of test methods.
  • Screenshots on failure speed up debugging.
  • Pick a tool that matches team size and need.

Reading a Report Like a Detective

Start with the summary counts. A sudden jump in failures after a code change points to a new defect. A single failure that appears only on one browser points to a browser-specific issue. Open the failed entry, read the message, and study the screenshot before touching any code. Compare the failure time with earlier builds; a test that failed yesterday and passed today without a code change signals a flaky test that needs a better wait.

Sharing Results with Non-Technical People

Managers care about three numbers: how many checks ran, how many passed, and which features carry risk. Add a short summary line at the top of the report, such as "Login and checkout verified; search has two open failures". Send the file by email or publish it on the team's shared page. Stakeholders open it without installing anything.