Image of a man working on his laptop and analyzing graphs and pie charts.Image of a man working on his laptop and analyzing graphs and pie charts.

Integration of Extent Reports

July 23, 2021
 by 
 Rohith Ramesh Rohith Ramesh
Rohith Ramesh

Integration of Extent Reports

As a software developer or tester, you are responsible for keeping track of your project launches, viewing and analyzing your test automation performance, comparing each execution category, tracking exceptions (if any), creating discussion topics, and searching entities from a myriad of options.

But what if you can create interactive and detailed test reports with real-time analytics such as events, screenshots, tags, etc. using a library? Well, it is possible with Extent Reports, which is the highlight of this article. In this article, we will talk about Extent Reports, their purpose, and then we will learn how to install and integrate them with Appium Javascript.

Also read: Integrating Audio APIs into Appium Automation Scripts

Introduction to Extent Reports

Extent Reports is an open-source library used for creating visually attractive reports during test automation. It produces HTML-based documents in graphs, pie charts, screenshots, custom logs, and test summaries in Java and .Net. The generated report can be shared with stakeholders using mails with several different functionalities. Due to its versatility and bundle of features, it’s one of the most used reporting libraries for Selenium tests.

When the automation test scripts are run, testers are required to generate a test execution report.

Benefits of Extent Reports

  • Extent reports can be easily integrated with TestNG, JUnit, and NUnit frameworks.
  • They allow capturing of the screenshots for each test step.
  • Testers can track multiple test case runs in a single test suite with Extent Reports.
  • It displays the time needed for executing a test.
  • It can be customized to represent each test step graphically.
  • It provides a delightful and responsive UI.
  • API utilization is extremely easy.
  • It coordinates with the test-runner logs easily.
  • It executes classes and strategies simultaneously.
  • It is configurable on the Jenkins server.
  • Multiple test case runs within a single suite can be tracked with Extent Reports.
Also check: Batching Appium Commands Using Execute Driver Script to Speed Up Tests

Purpose of the Extent Reports

The primary purpose of Extent Reports is to highlight the test case reports in a readable and interactive format that showcases real-time analytics as well. Hence, it is beneficial for the software developers and testers while executing the test cases of a project to display the attributes of the test report.

Extent reports are widely used in software organizations. The reporting they offer is mostly used by Selenium web drivers. Extent Reports are one of the best ways to generate customizable HTML reports with a delightful user interface in the Selenium web driver. It is the top choice for automation testers as it is an open-source library and can be easily configured with Selenium.

Check out: Selenium Automation Tips

Installation of Extent Reports

Installing Extent Reports is not a tedious process. It requires the following prerequisites to be installed in the system, followed by the steps for its installation.

Pre-requisites:

  • Java should be installed and set up.
  • TestNG should be installed.
  • Jar files of Extent Reports.
  • extent-config.xml to configure the HTML Report.

Steps for Installation:

1. Install and set up Java by

  1. Visiting the link https://jar-download.com/artifacts/com.aventstack/extentreports/3.1.5/source-code
  2. Downloading the zip file by clicking the ‘Download’ link, and extracting the zip in your local file system.
  3. Import the downloaded jar file by –
  4. Right-clicking on the project.
  5. Clicking on ‘Build  Path’ and then on ‘Configure Build Path’.
  6. Click on ‘Libraries’ and then on ‘Add External Jars’.
  7. Select the below Jar files in your local file system and click ‘Apply and Close’. The following code is used to include the ExtentReports dependency in the maven project:
  8. <dependency>
  9. <groupId>com.aventstack</groupId>
  10. <artifactId>extentreports</artifactId>
  11. </dependency>

Reporting the Test Reports

After the installation is complete, here are the steps to display the test reports using Extent Reports:

i. Report Initialization:

In the initial step of reporting, we need to first specify the file storage location. Then, create the HtmlReporter in that path and attach it with the Extent Report using the code:

String REPORTPATH = “Report/report.html”;

ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(REPORTPATH);

ExtentReports reporter = new ExtentReports();

Reporter.attachReporter(htmlReporter);
Copy

ii. Test Case and Test Steps Creation:

Build the test cases and steps report using the ‘createTest’ and ‘createNode’ methods:

ExtentTest testCaseA = reporter.createTest(“A”);

ExtentTest testStepA1 = testCaseA.createNode(“A1”);

testStepA1.log(Status.PASS,”details”);

ExtentTest testStepA2 = testCaseA.createNode(“A2”);

testStepA2.log(Status.PASS,”details”);
Copy

iii. Logging the Test Case Status:

The test case execution status is updated using the code:

testStepA.log(Status.PASS,”details);

testStepA.log(Status.FAIL,”details);

testStepA.log(Status.SKIP,”details);
Copy

iv. Author Name Assigning to the Test Cases:

Assigning the author name is useful if individuals are working on the same project using the code:

testCaseA.assignAuthor(“Test User1”);

testCaseB.assignAuthor(“Test User2”);
Copy

v. Test Case Category Assignment:

The categories of the report are assigned using the code:

testCaseA.assignCategory( “Regression Test”);

testCaseB.assignCategory (“System Test”);
Copy

vi. Adding Screenshot:

We need to log a screenshot in case of a failed test case to document the defects in the functionality with the code:

public void logScreenshot(WebDriver screenDriver) throws IOException{

try{

File file ={(TakeScreenshot)screenDriver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(file, new Filw(“sample.jpg”));

ExtentTest logger = this.childTest;

logger.fail(“Attached Screenshot”).addScreenCaptureFromPath(“sample.jpg”);

}

Catch(Exception ex){

           throw new CustomException(“Exception while taking the screenshots” .ex);

}

}
Copy

vii. Flushing the Report:

We need to write everything in the file after the report is created, and it could be viewed using the code:

reporter.flush();
Copy

viii. Configuring Extent Html Report:

The HTML reports can be customized using normal coding and XML config file as follows:

I. Normal Code

The test report title, encoding, protocol, theme, and other attributes can be configured with the code:

ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter (“Report/report.html”);

htmlReporter.config().setDocumentTitle(“Test Automation Report”);

htmlReporter.config().setProtocol(Protocol.HTTPS);

htmlReporter.config().setEncoding (“UTF-8”);

htmlReporter.config().setTheme (Theme.LIGHT);
Copy

II. xml config File Code:

You can customize the report using the xml file too using this code:

<extentreports>

<configuration>

<documentTitle>MST Automation Report</documentTitle>

<protocol>https</protocol>

<encoding>UTF-8</encoding>

<theme>standard</theme>

<reportName?align=“center”>

<![CDATA[

<img src=”../sample.png” style=”position:absolute;center:55px;”/>

<message> Automation Demo </message>

</reportName>

<testViewChartLocation>bottom</testViewChartLocation>

</configuration>

</extentreports>

This xml file is loaded into the html Extent Report using the code mentioned below:

ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(“Report/report.html”);

File file = new File (“extent_config.xml”);

htmlReporter.loadXMLConfig(file);  

Copy

View of the Test Report:

Dashboard View:

Test Report Dashboard View

Test Case View:

Test Case View

Author View:

Test Report Author View

Category View:

Category View

Exception View:

Exception View

Report Generator Code:

public class ReportGenerator{

ExtentTest childTest;

ExtentTest parentTest;

private static ExtentReports reporter =ExtentReportFactory.getReporter();

public void parentReport(String methodName,String author){

parentTest = reporter.createTest(methodName);

parentTest.assignAuthor(author);

 parentTest.assignCategory(“Demo Test cases”);

  public void childReport(String methodName){

  childTest = parentTest.createNode(methodName);

  childTest.log(Status.PASS, methodName);

public void flush(){

reporter.flush();

public void logScreenshot(WebDriver screenDriver, String testCaseName, String res, Exception e) throws IOException{

try{

File file=((TakesScreenshot)screenDriver).getScreenshotAs(OutputType.FILE);

File dir = new File(“Report/screenshot/”+testCaseName);

dir.mkdirs();

StringfileName=“Report/screenshot/”+testCaseName+“/”+testCaseName+“.jpg”;

FileUtils.copyFile(file, new File(fileName));

ExtentTest logger= this.childTest;

logger.fail(e);

logger.info(“Attachedscreenshot”).addScreenCaptureFromPath(“screenshot/”+testCaseName+“/”+testCaseName+“.jpg”);

catch(Exception ex){

throw new CustomException(“Exceptionwhiletakingscreenshot: “+ex);

publicvoidlogSkipTest(WebDriverscreenDriver,StringtestCaseName,Stringres)throws IOException{

Filefile=((TakesScreenshot)screenDriver).getScreenshotAs(OutputType.FILE);

File dir =new File(“Report/screenshot/”+testCaseName);

dir.mkdirs();

StringfileName=“Report/screenshot/”+testCaseName+“/”+testCaseName+“.jpg”;

FileUtils.copyFile(file, new File(fileName));

ExtentTest logger = this.childTest;

logger.skip(“Attachedscreenshot”).addScreenCaptureFromPath(“screenshot/”+testCaseName+“/”+testCaseName+“.jpg”); 

Copy

1. Integrating Extent Reports with Appium Script

Extent Reports can be integrated using the Appium script in the following way: Before executing the Appium script, make sure that you have downloaded all the jar files in your system required for your project.  Steps for Appium Script Execution:

  1. Create a Java Project under eclipse IDE.
  2. Add all the Appium dependency .jar files and Extent Report jars files to the project
  3. Create a config.xml file under the project folder and copy default xml content of extent report skeleton. Refer: htmlReporter.loadXMLConfig(“./config.xml”);
  4. Create an extentreport.html file under the project folder. Refer: private static String filePath = “./extentreport.html”;
  5. Create an ExtentManager.java default class under the project package where the Base class is created.
  6. Declare the classes and import the respective packages:
  7. import com.aventstack.extentreports.ExtentReports;
  8. import com.aventstack.extentreports.ExtentTest;
  9. import com.aventstack.extentreports.reporter.ExtentHtmlReporter; Classes: private static ExtentReports extent;
    private static ExtentTest test;
    private static ExtentHtmlReporter htmlReporter;
  10. Copy and Paste config.xml default xml script. into the config.xml file.
  11. Create an ExtentManager.java class.
  12. Create a Base class to add Appium capabilities or to launch the app.
  13. Create a @Test TestNG annotation method or test case in the same class.
  14. Create a testng.xml file under the project folder.
  15. Add xml content.
  16. Declare the class variables in the Base class of the Project:

public static ExtentReports extent;
public static ExtentTest test;

Copy
  1. Initialize extent class variable within the BeforeSuite Class:

extent = ExtentManager.GetExtent();

Copy
  1. Extend the Base class for the separate scenario class.
  2. Initialize test ExtentTest class variable into test case method:

test = extent.createTest(“TestCase1”, “Testcase Description”)

Copy
  1. Add the code to pass, fail or to get the logs from a particular test case method:

test.pass(objname +”Any Test Message”);   //Passed Test casetest.log(Status.FAIL,

register_button_displayed +” doesn’t contain “+”SignIn button” );

// Failed Test casetest.log(Status.ERROR, e.getMessage());   //Error message or log

Copy

Key Takeaway on Integration of Extent Reports

In this article, the usefulness of Extent Reports was mentioned along with how they make the life of software developers and testers easier by displaying test reports to project managers and stakeholders in a beautifully crafted manner. The installation of Extent Reports was also explained, along with how they are customized and displayed in different formats. Lastly, the integration code for Extent reports with the Appium Java Scripts was also demonstrated.

Read: Why Appium to Setup Mobile Testing Infrastructure

The Extent Report has many features to create a detailed test report, which could be incorporated into data-driven, hybrid, pom, and BDD frameworks. Thus, taking your project to a higher level. Install them today and realize their full potential.

FAQs

1. What are the three major frequently used classes of Extent Report in Selenium?

Ans: ExtentReports class, ExtentTest class, and ExtentHtmlReporter class.

2. What is Allure Report?

Ans: Allure Report is a flexible multi-language test report tool containing a detailed report on the conducted test in a web report form. It also allows users participating in the development process to extract the maximum of useful information from the everyday execution of tests.

3. What is Maven?

Ans: Maven is an open-source build tool to build, publish, and deploy several projects simultaneously for better project management. The tool enables developers to develop and document the lifecycle framework.

4. What is Reporter Class in TestNG? 

Ans: Reporter Class is an inbuilt class in TestNG and is available under the org.testng package. Reporter Class provides test styles to log dispatches that will be included in the HTML reports generated by TestNG. This class is one of the simplest ways of generating log information, where the logs in the reports can be either stoner-generated or system-generated reports.

Share this

Integration of Extent Reports

4 Parts