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
February 22, 2017

Generating Extent Reports – Java – Version3





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 using some of the methods provided by the extent reports classes.

We can provide below information to be displayed in the HTML report:

  1. Report Title
  2. Report Name
  3. PIE Chart Visibility
  4. PIE Chart Location
  5. Document Theme
  6. Operating System Name
  7. Hostname
  8. Environment Name
  9. User Name etc…

Below is the sample program:

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 GenerateExtentReport
{
    ExtentHtmlReporter htmlReporter;
    ExtentReports extent;
    ExtentTest test;
        
    @BeforeTest
    public void startReport()
    {
        htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);
        
        extent.setSystemInfo("OS", "Mac Sierra");
        extent.setSystemInfo("Host Name", "Krishna");
        extent.setSystemInfo("Environment", "QA");
        extent.setSystemInfo("User Name", "Krishna Sakinala");
        
        htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
        htmlReporter.config().setReportName("My Own Report");
        htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
        htmlReporter.config().setTheme(Theme.DARK);
    }
    
    @Test
    public void demoTestPass()
    {
        test = extent.createTest("demoTestPass", "This test will demonstrate the PASS test case");
        Assert.assertTrue(true);
    }
    
    @Test
    public void demoTestFail()
    {
        test = extent.createTest("demoTestFail", "This test will demonstrate the FAIL test case");
        Assert.assertTrue(false);
    }
    
    @Test
    public void demoTestSkip()
    {
        test = extent.createTest("demoTestSkip", "This test will demonstrate the SKIP test case");
        throw new SkipException("This test case not ready for execution");
    }
    
    @AfterMethod
    public void getResult(ITestResult result)
    {
        if(result.getStatus() == ITestResult.FAILURE)
        {
            test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Test case FAILED due to below issues:", ExtentColor.RED));
            test.fail(result.getThrowable());
        }
        else if(result.getStatus() == ITestResult.SUCCESS)
        {
            test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" Test Case PASSED", ExtentColor.GREEN));
        }
        else
        {
            test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" Test Case SKIPPED", ExtentColor.ORANGE));
            test.skip(result.getThrowable());
        }
    }
    
    @AfterTest
    public void tearDown()
    {
        extent.flush();
    }
}

In the above program, we have used three classes called ExtentHtmlReporter, ExtentReports and ExtentTest. These three classes will help us to create a rich HTML reports with lot of useful information. ExtentHtmlReporter 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. By using this we can set lot of configuration to the report. ExtentReports will be used to set the system/custom information in the generated HTML report. And ExtentTest will be used to log the so much information to the report like PASS, FAIL  and SKIP status of the executed tests. Along with this we can generate logs in the generated HTML report.

Important points to be remember:

  1. ExtentHtmlReporter will create the report file and set the configuration to the report.
  2. ExtentReports will set the system/custom information to the report.
  3. ExtentTest will log the information in the report.
  4. createTest() method of ExtentReports class is the starting point of the test and it will return the ExtentTest object.
  5. We need to capture that object into ExtentTest object.
  6. Used this reference to log the information into the report.
  7. ExtentHtmlReporter object will be used to add the report information like Title, Header and Theme etc..
  8. flush() method of ExtentReports will push/write everything to the document.





Output of the above program is:

Sample Extent Report - 1 Sample Extent Report - 2

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



Share this post: on Twitter on Facebook

Extent Reports Introduction – Java – Version3 Extent Reports Log Generation – Java – Version3

Related Posts

GENERATE EXTENT REPORT WITH MULTIPLE CLASSES JAVA

Extent Reports-Java-Version3

Extent Report With Multiple Classes

Capture FullPage Screenshot in Extent Reports – Java

Extent Reports-Java-Version3

Capture FullPage Screenshot in Extent Reports – Java

CAPTURE SCREENSHOTS IN EXTENT REPORTS JAVA

Extent Reports-Java-Version3

Capture Screenshot in Extent Reports – Java – Version3

EXTENT REPORTS LOG GENERATION JAVA

Extent Reports-Java-Version3

Extent Reports Log Generation – Java – Version3

EXTENT REPORTS INTRODUCTION JAVA

Extent Reports-Java-Version3

Extent Reports Introduction – Java – Version3

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