How to generate automation HTML report using extent report in selenium web driver and TestNG. Let’s see an example for the extent report in selenium. In the below example we are going to use extent report 4 with TestNG 7. 

Extent report in Selenium, TestNG

Extent reports, it’s a third-party framework that is used to generate meaning full and color full test results. It’s really important. when you run your automation test suite the results should be well defined and readable for everyone.

Steps to Generate extent report in Selenium

  • Install TestNG into your IDE (Eclipse TestNG integration)
  • Find maven dependency for extent report.
  • Create extend report configuration file (for good coding practice).
  • Integrate extent report with each of the testcase(@BeforeTest Annotation) 
  • Run the test suite and view the results.

for the below example, pre-requirements are  Eclipse TestNG integration and maven dependency for extent report.

Maven dependency for extent report 4

copy and paste below maven dependency for extent report into your pom.xml


Create extend report configuration class is a custom class that contains a static method ExtendReportConfiguraiton() 

package com.Extentreport;

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

public class ReportConfiguration {
 public static ExtentHtmlReporter htmlReporter;
 public static ExtentReports extent;
 public static ExtentTest logger;
 public  static void ExtendReportConfiguraiton() {
  htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") + "/test-output/ExtentReport.html");
  extent = new ExtentReports();
  extent.setSystemInfo("Host Name", "Bhupi");
  extent.setSystemInfo("Environment", "Automation Testing");
  extent.setSystemInfo("User Name", "gfgdfgfgd  SM");
  htmlReporter.config().setDocumentTitle("Auatomaiton Results");


new ExtentHtmlReporter(System.getProperty("user.dir") + "/test-output/ExtentReport.html")Will get the path of the project directory and create a folder “test-output” and an HTML file ExtentReport.html

new ExtentReports();Create an object of ExtentReports class.

attachReporter(htmlReporter);will attach your ExtentReport.html file with the ExtentReports object.

setSystemInfo() Will allow making more configuration in the HTML file.

Create TestCases using Selenium and TestNG is also a custom Java class that contains Initialize() method to define Browser drivers and base URL and also we have set the browser driver in the same.

Basically, This is a Page object format where we manage all the configuration and other resources in separate classes and objects.

package com.Extentreport;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class DriverContext {
      static WebDriver driver;
      public static String baseUrl = "";
   static String driverPath = "D:\\geckodriver.exe";
   public static WebDriver Initialize()
         System.setProperty("webdriver.gecko.driver", driverPath);
         driver = new FirefoxDriver();
         return driver;

}, Let’s create a test file and write some simple testcases in TestNG for the demo.

package com.Extentreport;

import org.openqa.selenium.*;
import org.testng.Assert;
import org.testng.annotations.*;

public class FirstTestNG extends ReportConfiguration {

 public WebDriver driver;

 public FirstTestNG() {
  driver = DriverContext.Initialize();

 public void startReport() {

 public void T1() {

 public void T2() {

  System.out.println("TestCase 2");
 public void T3() {

  System.out.println("TestCase 3");

Run the TestNG class

Right-click on the class –> Run As –> TestNG Test

Open Extent report in the browser

In your project directory open the “test-output” folder and run the file index.html on any real-time browser(Chrome or Firefox etc).


Extent report with multiple test classes and testcases

Yes, Most of the time will face issues to run the extent report with multiple classes and testcases. to achieve this we need to create a testng.xml that will run our test suite. (All Test Classes in a single run).

As we already have one test class,  So I am going to continue the same example, and let’s create another test class

package com.Extentreport;

import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class SecondTestNG {
 public WebDriver driver;
  public SecondTestNG() {
  driver = DriverContext.Initialize();

   public void Test1() {
         System.out.println("Test casesssssssss");

   public void Test3() {
   public void Test4() {

Create testng.xml

<!DOCTYPE suite SYSTEM "">	

<suite thread-count="1" verbose="1" name="Auto Suite" annotations="JDK" parallel="tests">
  <test name="flipkart">
    <class name="com.Extentreport.FirstTestNG"/>
    <class name="com.Extentreport.SecondTestNG"/>


The remaining configuration will be the same but to run the automation suite, we have to run the testng.xml

Right-click on the testng.xml–> Run As –> TestNG Test

Selenium Practice Task