Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
December 7, 2016

Generating Extent Reports – Java





Extent reports are very rich HTML reports for the selenium webdriver. This report will give so much of information about the execution status. The extra information can be provided from the external XML file. Once you create the XML file need to load in the program to read the configuration.

We can provide below information to the report using XML file:

  1. Report Title
  2. Report Name
  3. Report Headline
  4. Date Format
  5. Time Format

Apart from the above we can provide HostName, Environment Information and User Name etc… from the program.

Below is the sample program:

import java.io.File;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class GenerateExtentReport
{
    ExtentReports extent;
    ExtentTest test;
        
    @BeforeTest
    public void startReport()
    {
        extent = new ExtentReports(System.getProperty("user.dir") +"/test-output/MyOwnReport.html", true);
        extent
        .addSystemInfo("Host Name", "Krishna")
        .addSystemInfo("Environment", "QA")
        .addSystemInfo("User Name", "Krishna Sakinala");
        extent.loadConfig(new File(System.getProperty("user.dir")+"\\extent-config.xml"));
    }
    
    @Test
    public void demoReportPass()
    {
        test=extent.startTest("demoReportPass");
        Assert.assertTrue(true);
        test.log(LogStatus.PASS, "Assert Pass as condition is True");
    }
    
    @Test
    public void demoReportFail()
    {
        test=extent.startTest("demoReportFail");
        Assert.assertTrue(false);
        test.log(LogStatus.FAIL, "Assert Fail as condition is False");
    }
    
    @AfterMethod
    public void getResult(ITestResult result)
    {
        if(result.getStatus()==ITestResult.FAILURE)
        {
            test.log(LogStatus.FAIL, result.getThrowable());
            
        }
        extent.endTest(test);
    }
    
    @AfterTest
    public void endreport()
    {
        extent.flush();
        extent.close();
    }
}

In the above program, we have used two classes called ExtentReports, ExtentTest. These two classes objects will help us to create a rich HTML reports with lot of useful information. ExtentReports  will take the HTML report file path as an argument and it will create the report file with the mentioned name in the mentioned location. And ExtentTest will be used to log the so much information to the report like PASS, FAIL  and SKIP status of the executed tests.

Important points to be remember:

  1. ExtentReports will create the report file.
  2. ExtentTest will log the information in the report.
  3. startTest() method of ExtentReports class is the starting point of the test and it will return the ExtentTest object.
  4. We need to capture that object into ExtentTest object.
  5. Used this reference to log the information into the report.
  6. ExtentReports object will be used to add the report information like Title, Header and Theme etc..
  7. And the above configuration need to passed from the external XML file using loadConfig() method of ExtentReports class. It will take the XML file path as argument.
  8. endTest() method of ExtentReports will stop capturing information about the test log.
  9. flush() method of ExtentReports wil push/write everything to the document.
  10. close() method of ExtentReports will clear/close all resource of the ExtentReports object.





Below is the sample configuration file:

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

  
    <!-- report theme -->
    <!-- standard, dark -->
    standard
  
    <!-- document encoding -->
    <!-- defaults to UTF-8 -->
    UTF-8
    
    <!-- protocol for script and stylesheets -->
    <!-- defaults to https -->
    https
    
    <!-- title of the document -->
    ExtentReports 2.0
    
    <!-- report name - displayed at top-nav -->
    Automation Report
    
    <!-- report headline - displayed at top-nav, after reportHeadline -->
    
    
    <!-- global date format override -->
    <!-- defaults to yyyy-MM-dd -->
    yyyy-MM-dd
    
    <!-- global time format override -->
    <!-- defaults to HH:mm:ss -->
    HH:mm:ss
    
    <!-- custom javascript -->
    <scripts>
      <![CDATA[ $(document).ready(function() { }); ]]>
    </scripts>
    
    <!-- custom styles -->
    <styles>
      <![CDATA[ ]]>
    </styles>
  </configuration>
</extentreports>

This ways we can configure the report information and can generate the extent reports.

Output of the above program is:

ExtentReport 1 ExtentReport 2

Please watch the YouTube video of this blog for better understanding.



Share this post: on Twitter on Facebook

Extent Reports Introduction – Java Extent Reports Log Generation – Java

Related Posts

CAPTURE SCREENSHOTS IN EXTENT REPORTS - JAVA

Extents Reports - Java

Capture Screenshot in Extent Reports – Java

LOG GENERATION IN EXTENT REPORTS JAVA

Extents Reports - Java

Extent Reports Log Generation – Java

EXTENT REPORTS INTRODUCTION JAVA

Extents Reports - Java

Extent Reports Introduction – Java

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025