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, and their purpose, and then we will learn how to install and integrate them with Appium Javascript.
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.
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:
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:
<dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> </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);
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”);
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);
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”);
v. Test Case Category Assignment:
The categories of the report are assigned using the code:
testCaseA.assignCategory( “Regression Test”);
testCaseB.assignCategory (“System Test”);
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);
}
}
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();
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);
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”>
<
Abhay
Abhay
I am a digital marketer with 13+ yrs. experience. I have written so many blogs and also have sound knowledge in software testing.