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.
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.
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.
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.
- 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
- Visiting the link https://jar-download.com/artifacts/com.aventstack/extentreports/3.1.5/source-code
- Downloading the zip file by clicking the ‘Download’ link, and extracting the zip in your local file system.
- Import the downloaded jar file by –
- Right-clicking on the project.
- Clicking on ‘Build Path’ and then on ‘Configure Build Path’.
- Click on ‘Libraries’ and then on ‘Add External Jars’.
- 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:
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:
ii. Test Case and Test Steps Creation:
Build the test cases and steps report using the ‘createTest’ and ‘createNode’ methods:
iii. Logging the Test Case Status:
The test case execution status is updated using the code:
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:
v. Test Case Category Assignment:
The categories of the report are assigned using the code:
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:
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:
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:
II. xml config File Code:
You can customize the report using the xml file too using this code:
<documentTitle>MST Automation Report</documentTitle>
<img src=”../sample.png” style=”position:absolute;center:55px;”/>
<message> Automation Demo </message>
This xml file is loaded into the html Extent Report using the code mentioned below:
View of the Test Report:
Test Case View:
Report Generator Code:
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:
- Create a Java Project under eclipse IDE.
- Add all the Appium dependency .jar files and Extent Report jars files to the project
- Create a config.xml file under the project folder and copy default xml content of extent report skeleton. Refer: htmlReporter.loadXMLConfig(“./config.xml”);
- Create an extentreport.html file under the project folder. Refer: private static String filePath = “./extentreport.html”;
- Create an ExtentManager.java default class under the project package where the Base class is created.
- Declare the classes and import the respective packages:
- import com.aventstack.extentreports.ExtentReports;
- import com.aventstack.extentreports.ExtentTest;
- import com.aventstack.extentreports.reporter.ExtentHtmlReporter; Classes: private static ExtentReports extent;
private static ExtentTest test;
private static ExtentHtmlReporter htmlReporter;
- Copy and Paste config.xml default xml script. into the config.xml file.
- Create an ExtentManager.java class.
- Create a Base class to add Appium capabilities or to launch the app.
- Create a @Test TestNG annotation method or test case in the same class.
- Create a testng.xml file under the project folder.
- Add xml content.
- Declare the class variables in the Base class of the Project:
- Initialize extent class variable within the BeforeSuite Class:
- Extend the Base class for the separate scenario class.
- Initialize test ExtentTest class variable into test case method:
- Add the code to pass, fail or to get the logs from a particular test case method:
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.
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.