Extension to Extent Report 3


         This article is an extension of Extent Report TestNG which helps you to use the latest Extent report library 4 series introduced by aventstack. This is the time to migrate version 3 to 4. Here I would like to share the basic changes in version 4. The first thing is ExtentHtmlReporter class deprecated and introduced ExtentSparkReporter.

      ExtentSparkReporter is the default version 4 reporter supporting both BDD and non-BDD test styles. The ExtentSparkReporter creates a rich standalone spark file. It allows several configuration options via the config() method. In the new version, no need to load the extent-config.xml via code. The library itself configure the default style for the HTML report but we have to specify the directory path to store HTML report before start the test suite. We can also specify the themes for the HTML report, it supports DARK and STANDARD themes.

   As usual, the object of ExtentReports class helps to attach the object of ExtentSparkReporter and also to set system information in the HTML file, map each test into the HTML report. Finally, we have to flush the object o ExtentReports class. The object of ExtentTest class helps to keep track of the status of each test case into the HTML report with assign specific color for the test.

Prerequisites to Generate Extent Reports:

  1. Java should be installed and setup Java
  2. TestNG maven dependency should be available
  3. Extent Report Maven dependency should be available


Below is the code snippet for before suite,

public static ExtentSparkReporter sparkReporter;
public static ExtentReports extentReport;
String reportPath = System.getProperty(“user.dir”) + “/AutomationReport/”;

sparkReporter = new ExtentSparkReporter(reportPath);
sparkReporter.config().setDocumentTitle(“Appium Automation”);
sparkReporter.config().setReportName(“Automation Execution Report”);
extentReport = new ExtentReports();
extentReport.setSystemInfo(“Application Name”, “ExtentReport”);
extentReport.setSystemInfo(“Platform”, System.getProperty(“os.name”));
extentReport.setSystemInfo(“Environment”, “QA”);

     Below is the code snippet to collect the test method name prior to each test execution. This logic you can add before method section,

String className = this.getClass().getSimpleName();
extentTest = extentReport.createTest(className + “-” + method.getName()); //method object of Method class should be passed to get the method name.

     Below is the code snippet to collect the test results after each test execution and map those results into the HTML report. You can use the below logic after method section,

public static ExtentTest extentTest;

String methodName = result.getName();
if (result.getStatus() == ITestResult.FAILURE) {
extentTest.log(Status.FAIL, MarkupHelper.createLabel(methodName + ” – Test Case Failed”, ExtentColor.RED));
MarkupHelper.createLabel(result.getThrowable() + ” – Test Case Failed”, ExtentColor.RED));
// Here you can add screenshot in the report for fail case
extentTest.fail(methodName + “Test Step Failed”);
if (result.getStatus() == ITestResult.SKIP) {
MarkupHelper.createLabel(result.getName() + ” – Test Case Skipped”, ExtentColor.ORANGE));
extentTest.skip(methodName + “Test Step Skipped”);
if (result.getStatus() == ITestResult.SUCCESS) {
MarkupHelper.createLabel(result.getName() + ” Test Case PASSED”, ExtentColor.GREEN));
extentTest.pass(methodName + “Test Step Passed”);

     The below final code snippet helps to flush the object of the ExtentReports class and also rename the generated file name with time-stamp. By default, the library will generate index.html file. After suite, we can rename the HTML report along with flushing the object of the ExtentReports class.

DateFormat dateFormat = new SimpleDateFormat(“dd-MMM-yyyy_HH-mm-ss”);
Date date = new Date();
String filePathdate = dateFormat.format(date).toString();
String actualReportPath = reportPath + “index.html”;
new File(actualReportPath).renameTo(new File(
System.getProperty(“user.dir”) + “/AutomationReport/” + “Automation_” + filePathdate + “.html”));

Below are the sample screenshots of the generated HTML report.




Try to migrate your extent report 3 versions to 4 series and enjoy the differences.

make it perfect!

Extent Reports in Automation – TestNG


     TestNG itself, providing an HTML report in test-output folder. I had a thought of building custom report for automation, after that I built one PDF customized report using iText PDF Java library and took more effort to build it. Later I thought to build a custom beautiful high rich HTML reports with minimum effort; that time Extent Report comes into my mind. Here, I would like to share the details on the integration and implementation of Extent Report utility in Automation test classes that built with TestNG.

Prerequisites to Generate Extent Reports:

  1. Java should be installed and setup Java
  2. TestNG maven dependency should be available
  3. Selenium maven dependency should be available
  4. Extent Report Maven dependency should be available
  5. extent-config.xml – It allows to configure HTML Report

Steps To Generate Extent Reports:

  1. Firstly, create a maven project.
  2. Add TestNG dependency to pom.xml of project in eclipse.
  3. Add selenium-java and selenium-server dependencies to pom.xml of  project in eclipse
  4. Extent Report Maven dependency (version: 2.41.2) should available and added in pom.xml project in eclipse.
  5. Create a java class say ‘SeleniumExtentReport’ and add following code to it,

package com.journeyofquality.test;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class SeleniumExtentReport {
ExtentReports extentReport;
ExtentTest extentTest;
WebDriver driver;

public void beforeSuite() {
//In before suite we are creating HTML report template, adding basic information to it and load the extent-config.xml file

extentReport = new ExtentReports(System.getProperty(“user.dir”) + “/test-output/SeleniumExtentReport.html”,
extentReport.addSystemInfo(“Host Name”, “JourneyofQuality”).addSystemInfo(“Environment”, “Automation Testing”)
.addSystemInfo(“User Name”, “Sanoj”);
extentReport.loadConfig(new File(System.getProperty(“user.dir”) + “\\extent-config.xml”));

public void beforeClass() {
System.setProperty(“webdriver.chrome.driver”, );
driver = new ChromeDriver();

public void beforeMethod(Method method) {
//In before method we are collecting the current running test case name
String className = this.getClass().getSimpleName();
extentTest = extentReport.startTest(className + “-” + method.getName());

public void passTest() {

public void failTest() {
Assert.assertEquals(driver.getTitle().toString(), “Journey”);

public void skipTest() {
throw new SkipException(“Skipping – This is not ready for testing “);

public void getResult(ITestResult result, Method method) throws Exception {
//In after method we are collecting the test execution status and based on that the information writing to HTML report
if (result.getStatus() == ITestResult.FAILURE) {
extentTest.log(LogStatus.FAIL, “Test Case Failed is ” + result.getName());
String screenshotPath = SeleniumExtentReport.capture(driver, result.getName());
extentTest.log(LogStatus.FAIL, “Error Details :- \n” + result.getThrowable().getMessage()
+ extentTest.addScreenCapture(screenshotPath));
if (result.getStatus() == ITestResult.SKIP) {
extentTest.log(LogStatus.SKIP, “Test Case Skipped is ” + result.getName());
if (result.getStatus() == ITestResult.SUCCESS) {
extentTest.log(LogStatus.PASS, “Test Case Passed is ” + result.getName());

public void endReport() {
//In after suite stopping the object of ExtentReports and ExtentTest


* To Capture the Screenshot and return the file path to extent report fail
* cases
* @param driver
* @param screenShotName
* @return
* @throws IOException
private static String capture(WebDriver driver, String screenShotName) throws IOException {
String dest = null;
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(“dd-mm-yyyy h-m-s”);
Date date = new Date();
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
dest = System.getProperty(“user.dir”) + “\\ErrorScreenshots\\” + screenShotName + dateFormat.format(date)
+ “.png”;
File destination = new File(dest);
FileUtils.copyFile(source, destination);
} catch (Exception e) {
return dest;

Code Explanation:

  • Imported two classes ExtentReports and ExtentTest.
    • ExtentReportsBy using this class we set the path where our reports need to generate.
    • ExtentTestBy using this class we could generate the logs in the report.
  • Took three methods with @Test annotation such as passTest, failTest and skipTest and a method beforeSuite with @BeforeSuite annotation, beforeMethod with @BeforeMetod annotation, another method getResult with @AfterMethod annotation and finally, endReport with @AfterSuite annotation.
  • Here my intention is to generate a report with all the three types of results such as Pass, Fail and Skip.
  • Used object of ExtentReports class (i.e., extentReport) in the beforeSuite method which was assigned to @BeforeSuite annotation to generate the HTML report in the required path.
  • Used object of ExtentTest class (i.e., extentTest) in beforeMethod to get the name of currently executing test case. Also, extentTest object used in getResult method which was assigned to @AfterMethod annotation to write logs in the report.
  • Used ITestResult class in the @AfterMethod to describe the result of a test.


     By using this external XML file (extent-config.xml), we could change the details such as Report Theme (either standard or dark), Report Title, Document Title etc., We use extent object and use loadConfig() method to load this XML file.

<?xml version=”1.0″ encoding=”UTF-8″?>
<!– report theme –>
<!– standard, dark –>
<!– document encoding –>
<!– defaults to UTF-8 –>
<!– protocol for script and stylesheets –>
<!– defaults to https –>
<!– title of the document –>
<!– report name – displayed at top-nav –>
<!– report headline – displayed at top-nav, after reportHeadline –>
<reportHeadline>Automation Report</reportHeadline>
<!– global date format override –>
<!– defaults to yyyy-MM-dd –>
<!– global time format override –>
<!– defaults to HH:mm:ss –>
<!– default style override –>
<!– custom javascript –>
$(document).ready(function() {
$(‘#parentNodes’).prop(“checked”, true).click();
$(‘#test-count-setting > div.modal-footer > a’)[0].click();
<!– custom styles –>

     Refresh the project after execution of above SeleniumExtentReport.java file. You could find an HTML file named “SeleniumExtentReport.html” in your test-output folder. Copy the location of the “SeleniumExtentReport.html” file and open it by using any browser. You could see beautiful high rich HTML reports as shown below.



Try to implement the above mentioned custom report mechanism in your Selenium – Java -TestNG and enjoy automation.

make it perfect !