Extent Reporting Tool with Selenium

Extent Reporting Tool with Selenium

Reporting is a crucial component of any good test automation framework. It is important to present the result of the test automation runs in an effective manner, helping the business to take important decision. It also helps testers to provide meaningful feedback to the developers to inform them about the build health across the build cycles. Thus great reporting helps everyone in the team to visualize the take decisions about the product as the build health status graph shows across test automation runs.

There are a lot of tools available which can be integrated with tools like Selenium like testng, junit, allure, extent for great reporting framework. In this article we will explore the Extent Reporting tool integration with Selenium.

What is Extent

Extent Reports are logger style API written for Java and .Net environments, which allow creating HTML reports from test. The official website of extent reports is - http://extentreports.com/. It is available in the community edition and business edition. ExtentAPI allows to, create beautiful as well as interactive HTML reports. With the help of different configuration options provided we can display the statistics generated in a customizable manner.

Implementation of Extent Report

To implement extent report we will proceed with the following project settings –

a.       Create a maven simple project

b.      Create a testng class in the test folder.

We need to add the extent-config.xml file in the folder. Please find it here-

<?xml version="1.0" encoding="UTF-8"?>







        <reportName>Automation Report</reportName>




                $(document).ready(function() {












We will now add the dependencies needed for extent reports in the pom.xml file of maven project. Along with this we will have dependencies added for selenium, testng.



















We will now have our LoginLogout Scenario from our demo application – http://5elementslearning.com/demosite.  The scenario steps are –

a.       Open the application

b.      Click my account link

c.       Type registered username

d.      Type registered password

e.      Click sign in button

f.        Click log off link

g.       Click continue button

Let’s see the test method – selenium+chrome+testng


  public void testLogin() throws Exception {

driver.get(baseUrl + "/demosite/");
 driver.findElement(By.linkText("My Account")).click();
driver.findElement(By.linkText("Log Off")).click();



We now create another class, called as ExtentReportsExample, where we implement few annotations.

In @BeforeTest – we establish the configuration for the report file. We then create @Test methods for the pass, fail and skip tests. In the @AfterMethod, we mark the test in color as per their status of pass, fail or skip. The entire code for it is available here –

package MavenProjectwithReporting.ReportingProject;


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.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 extentReportExample{

        ExtentHtmlReporter htmlReporter;

        ExtentReports extent;

        ExtentTest logger;



        public void startReport(){


                htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/ExtentReport.html");

                extent = new ExtentReports ();


                extent.setSystemInfo("Host Name", "5 Elements Learning");

                extent.setSystemInfo("Environment", "Test Automation");

                extent.setSystemInfo("User Name", "Pallavi Sharma");


                htmlReporter.config().setDocumentTitle("Extent Report Example");







        public void passTest(){

                logger = extent.createTest("passTest");


                logger.log(Status.PASS, MarkupHelper.createLabel("Test Case Passed is passTest", ExtentColor.GREEN));




        public void failTest(){

                logger = extent.createTest("failTest");


                //logger.log(Status.PASS, "Test Case (failTest) Status is passed");

                //logger.log(Status.PASS, MarkupHelper.createLabel("Test Case (failTest) Status is passed", ExtentColor.GREEN));




        public void skipTest(){

                logger = extent.createTest("skipTest");

                throw new SkipException("Skipping - This is not ready for testing ");




        public void getResult(ITestResult result){

                if(result.getStatus() == ITestResult.FAILURE){

                        //logger.log(Status.FAIL, "Test Case Failed is "+result.getName());

                        //MarkupHelper is used to display the output in different colors

                        logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " - Test Case Failed", ExtentColor.RED));

                        logger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + " - Test Case Failed", ExtentColor.RED));

                }else if(result.getStatus() == ITestResult.SKIP){

                        //logger.log(Status.SKIP, "Test Case Skipped is "+result.getName());

                        logger.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + " - Test Case Skipped", ExtentColor.YELLOW));  




        public void endReport(){





Output Result File

The extent report output html file will get generated in the test-output folder. Here’s a screenshot of the one attached for our test –



Hope the above article helps you implement extent reports in your projects. There is also a lot of material about the same topic available on the internet by a variety of bloggers. Please feel free to explore more and keep discovering and learning. 

No comments

Leave a reply

Your email is never published nor shared. Required fields are marked *