Creating extent reports in selenium webdriver example

Extent Reports are the most popular reporting used with Selenium. As we all know, TestNG generates html reports by default but they are not more readable and interactive, we have to put lots of efforts to make it attractive. TestNG has provided an ability to implement 'IReporter' an interface to customize testng report by users.

ExtentReport API makes our life easy to generate interactive report with simple configuartions. It supports almost all Java and .NET test frameworks such as TestNG, JUnit, NUnit etc.

Extent Report Maven Dependency :


Let's understand with the help of basic example how extent reports work with selenium webdriver And later will look at advanced example on extent report

Step 1 :- Create maven project, create a class '' and add the below code : -

package com.extentreport;

import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;
public class BasicExtentReport {
	//builds a new report using the html template 
    ExtentHtmlReporter htmlReporter;
    ExtentReports extent;
    //helps to generate the logs in test report.
    ExtentTest test;
    @Parameters({ "OS", "browser" })
    public void startReport(String OS, String browser) {
    	// initialize the HtmlReporter
        htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/testReport.html");
        //initialize ExtentReports and attach the HtmlReporter
        extent = new ExtentReports();
        //To add system or environment info by using the setSystemInfo method.
        extent.setSystemInfo("OS", OS);
        extent.setSystemInfo("Browser", browser);
        //configuration items to change the look and feel
        //add content, manage tests etc
        htmlReporter.config().setDocumentTitle("Extent Report Demo");
        htmlReporter.config().setReportName("Test Report");
        htmlReporter.config().setTimeStampFormat("EEEE, MMMM dd, yyyy, hh:mm a '('zzz')'");
    public void testCase1() {
        test = extent.createTest("Test Case 1", "PASSED test case");
    public void testCase2() {
        test = extent.createTest("Test Case 2", "PASSED test case");
    public void testCase3() {
        test = extent.createTest("Test Case 3", "PASSED test case");
    public void testCase4() {
        test = extent.createTest("Test Case 4", "PASSED test case");
    public void testCase5() {
        test = extent.createTest("Test Case 5", "SKIPPED test case");
        throw new SkipException("Skipping this test with exception");
	public void testCase6(){
			test = extent.createTest("Test Case 6", "I'm Not Ready, please don't execute me");
    public void getResult(ITestResult result) {
        if(result.getStatus() == ITestResult.FAILURE) {
            test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" FAILED ", ExtentColor.RED));
        else if(result.getStatus() == ITestResult.SUCCESS) {
            test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" PASSED ", ExtentColor.GREEN));
        else {
            test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" SKIPPED ", ExtentColor.ORANGE));
    public void tearDown() {
    	//to write or update test information to reporter

'ExtentHtmlReporter' creates a rich standalone HTML file. It accepts ExtentHtmlReporter( file) and ExtentHtmlReporter(java.lang.String filePath). In the above code, we are passing file path where the reports will be saved.

'ExtentHtmlReporter' also allows several configuration options via the config() method. In the above code, we have added few configuration items to change the look and feel of the report like report name, time stamp etc.

In 'AfterMethod', we are getting the status of each test executed and updating the status with Fail, Pass and Skip. If the test is failed, we are getting message string that gives more information about the errorresult.getThrowable()

MarkupHelper - MarkupHelper class is used to create labels like 'PASSED' / 'FAILED' and also to give colors to the different status in the test report using ExtentColor enum.

Step 2 :- Create testng.xml file like below to pass OS and Browser parameters : -

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "" >
<suite name="Main Test Suite" verbose="5">

<parameter name="OS" value="Windows"/>
<parameter name="browser" value="Chrome"/>

  <test name="Extent Report Test">
     <class name="com.extentreport.BasicExtentReport"/>

Step 3 :- Add below code to your pom.xml file

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
   <!--Test reporting library - extent 3.X-->

<!-- -->
<!-- -->


Once we run the program, you should the report like below : -
Below is the output image :-

Testng report after executing selenium

Below is the Extent Report HTML looks like : -

Extent html report dashboard

If you want to view the failure reason, you just need to click on failed test case which will show the status of the test and the reason of the failure (exception details). Below is the failed test case view.

Extent html report failure test case

In this example, we have just seen how the basic extent reports work and how the reports look like. We will discuss more details on Extent report in next tutorials using test listeners and selenium webdriver

Selenium Tutorials: 


Hi Sir,

Am facing below error while excuting the above code. Please help me out for this.

[RemoteTestNG] detected TestNG version 6.10.0
org.testng.TestNGException: Read timed out
at org.testng.TestNG.initializeSuitesAndJarFile(
at org.testng.remote.AbstractRemoteTestNG.initialize(
at org.testng.remote.RemoteTestNG.initAndRun(
at org.testng.remote.RemoteTestNG.main(
Caused by: Read timed out
at Method)

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.