How to use ExtentReport in a framework

29 / Jun / 2016 by Kimi Agarwal 17 comments

The other day while I was executing my TestNG test cases in the Selenium WebDriver, all my test cases got executed, and the report also showed correctly. However, I usually don’t find its user interface very friendly especially when it’s about creating reports. That’s when I came across a user friendly reporting tool called ExtentReport.

ExtentReport is an HTML reporting library for Java, which can be used with Selenium WebDriver. We can use this tool within our TestNG automation framework. As an automation tester, it’s expected of you to provide detailed yet reports and present it to the administration group. ExtentReport is a simple to use tool to make excellent execution reports.

Process to Set up ExtentReport:

  1. Install and set up Java on your system.
  2. Now setup Eclipse.
  3. Launch Eclipse and create a Maven project.
  4. Add Selenium, TestNG, ExtentReport dependency in the pom.xml file.

ExtentReport dependency in our maven project, use the below snippet:-


Use Case in which we are going to mechanize

  1. Check the current URL of the web page
  2. Enter invalid email id in the Sign Up content box
  3. Click on the Sign Up button
  4. To verify the error message.

Create a Simple TestNG Script
Following is the code snippet for our use case.


  1. startTest(“TestCaseName”, “Description”) : It starts the current test.

            TestCaseName – It will print the name of the Test Case in the Report.
            Description – It will print the description of the Test case.

  1. assignAuthor(“AuthorName”) : Test case designer name is mentioned here.
  2. assignCategory(“CategoryName”) : Category of the Test Case displays here.
  3. log(LogStatus.PASS, “Step details”): It’s a repository which keeps the information about the test cases whether passed or failed.
  4. endTest(test) : Current test case ends here.
  5. flush() : Once the session is finished, specifically call the flush method.
  6. close() : Call this method at the very end in the @AfterSuite annotation, it ought to be called just once.

Following is the ‘extent-config.xml’ snippet.


Once the test cases are run successfully, the report will be created under your folder. Now, go to the folder and view the .html report.
For e.g.: The path of the report will be D:\MyExtentReport.html

ExtentReport Architecture
After executing the test cases, the ExtentReport design will look like this.


three four

In this report, the main page is the dashboard where:-

  • You can view the total number of test cases and test steps
  • Start time and End time are displayed
  • Number of test cases passed, failed, skipped, and so on information is provided
  • Number of steps of test cases passed, failed, and so on data is given
  • Pass Percentage of total number of test cases is given
  • Category Name of the test cases is likewise shown on the dashboard.

Clicking on the middle tab, I will be able to see the suite level information and its status (whether it’s pass or fail). On clicking the respective test case name, it will show the test case details: its start time, end time and execution time.

Points of interest of ExtentReport

  1. Open source reporting library.
  2. Provide delightful and responsive UI.
  3. Gives dashboard to the whole run.
  4. Exceptionally easy to utilize API.
  5. Effortlessly coordinate test-runner logs.
  6. Parallel execution of classes and strategies upheld.
  7. It can also be configured on Jenkins server.

It’s a useful storehouse having an extraordinary HTML reporting feature. Automation Testers ought to utilize this report because of its effective reporting by which anybody can understand easily which test case is working appropriately and which falls flat.



comments (17)

  1. Vivek Vasu

    I am getting the below error.Could you please help me?
    java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException

  2. Seema

    Can you please share the config file too.Thanks a lot for the detailed explanation.It is really helpful.

  3. Sridhar

    I want to generate test results in Extent Reports. My requirements is for Parallel execution. Each testsuite has same cases and executes in parallel mode. Now I want to see the both testsuite results in Extnet reports. Is there any way to view both TestSuite results in one Extent report?

    Please help me. Thank you!

  4. Richa

    Here screenshots are getting stored at local folder which html report refers.
    If I want to share these reports with someone, how he would be see the screenshots in that case.

  5. Jain

    I have issue with ‘extent reports’ display in the browser. Our proxy server doesn’t allow the sites to render Java script and CSS. How can I work around this? Are you familiar with any security threats using this ‘extent reports’?

    1. Kimi AgarwalKimi Agarwal

      ‘extent-config.xml’ helps us in customizing our report file.
      Please find the attached snippet for ‘extent-config.xml’ in my blog it might help you.

    1. Kimi AgarwalKimi Agarwal

      For Protractor, you can design your report using Allure Reporting. ExtentReport is not supported for the JavaScript project.


    Wonderful explanation and review of extentreport. I certainly enjoyed it. It would have been one point solution for me if has covered mailing of this report to business/team post execution. But nevertheless, v. good effort to have very detail review of the report and hope to have many more articles. Cheers !

    1. Kimi AgarwalKimi Agarwal

      As you can see the ‘TestNG Script’. So in that script, you can add more than one Test method then you will be able to see the result in ExtentReport.

      1. Gurpreet Singh

        I am getting an exception while creating an instance of ExtentReports
        extent = new ExtentReports(“C:\\Selenium_Luna\\MyMaven_DataDrivenFramework\\reports\\”+fileName, true, DisplayOrder.NEWEST_FIRST);
        Cannot instantiate class com.selenium.testng.ddf.testcases.LoginTest
        at org.testng.internal.ObjectFactoryImpl.newInstance(
        at org.testng.internal.ClassHelper.createInstance1(
        at org.testng.internal.ClassHelper.createInstance(
        at org.testng.internal.ClassImpl.getDefaultInstance(
        at org.testng.internal.ClassImpl.getInstances(
        at org.testng.TestClass.getInstances(
        at org.testng.TestClass.initTestClassesAndInstances(
        at org.testng.TestClass.init(
        at org.testng.TestClass.(
        at org.testng.TestRunner.initMethods(
        at org.testng.TestRunner.init(
        at org.testng.TestRunner.init(
        at org.testng.TestRunner.(
        at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(
        at org.testng.SuiteRunner.init(
        at org.testng.SuiteRunner.(
        at org.testng.TestNG.createSuiteRunner(
        at org.testng.TestNG.createSuiteRunners(
        at org.testng.TestNG.runSuitesLocally(
        at org.testng.TestNG.runSuites(
        at org.testng.remote.RemoteTestNG.initAndRun(
        at org.testng.remote.RemoteTestNG.main(
        Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.testng.internal.ObjectFactoryImpl.newInstance(
        … 25 more
        Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at Source)
        at Source)
        at$100(Unknown Source)
        at$ Source)
        at$ Source)
        at Method)
        at Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
        at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
        at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
        at com.relevantcodes.extentreports.Configuration.getConfigurationMap(
        at com.relevantcodes.extentreports.Report.loadConfig(
        at com.relevantcodes.extentreports.Report.(
        at com.relevantcodes.extentreports.ExtentReports.(
        at com.relevantcodes.extentreports.ExtentReports.(
        at com.selenium.testng.ddf.basetest.ExtentManager.getInstance(
        at com.selenium.testng.ddf.basetest.BaseTest.(
        at com.selenium.testng.ddf.testcases.LoginTest.(
        … 30 more
        Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
        at Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        … 60 more

        1. Kimi AgarwalKimi Agarwal

          Please use this.

          String workingDir = System.getProperty(“user.dir”);
          System.out.println(“Current working directory : ” + workingDir);
          extent = new ExtentReports(workingDir+”/Test_Execution_Report.html”, true,DisplayOrder.NEWEST_FIRST);
          extent.loadConfig(new File(workingDir+”/extent-config.xml”));

          1. Kimi AgarwalKimi Agarwal

            You can use this script.
            package com.DoTrips;

            import com.relevantcodes.extentreports.ExtentReports;
            import com.relevantcodes.extentreports.ExtentTest;
            import com.relevantcodes.extentreports.LogStatus;

            public class Demo {
            public static ExtentReports extent;
            public static ExtentTest test;
            public static void main(String []args){
            extent = new ExtentReports(“D://Report//advanceExtentReport.html”,true);
            ExtentTest test = extent.startTest(“My First Test”, “Sample description”);
            test.log(LogStatus.PASS, “hello test”);

Leave a comment -