Login

Integration of Extent Reports to Test Automation Frameworks

- By Sri harsha

Extent Report is an open source test reporting utility which can be integrated to any Test automation framework. This provides the capability to get pie charts of the test results, test summary, detailed log level report, environment information, various filters to get results, screenshots etc.

It also provides the execution time for each test cases and can be integrated with test frameworks like JUnit and TestNG.

How to Integrate with Test Automation Frameworks ?

Import the ExtentReport library to your framework based on the build systems that is being used.

Maven:

<dependency>
    <groupId>com.relevantcodes</groupId>
    <artifactId>extentreports</artifactId>
    <version>2.41.2</version>
</dependency>

Gradle:

compile group: 'com.relevantcodes', name: 'extentreports', version: '2.41.2'

Once the library is imported, create a class file which can be used to create wrapper functions using extentreport methods.

/**
 * This file consists of code related to Extent reports which generates a report
 * file after each test execution
 *
 */
public class ExtentResults {

	public static ExtentReports extentReports = new ExtentReports(Configurations.resultsPath, true);
	public static ExtentTest log;

	public void createTestcase(String testcasename, String testname) throws Exception {

		log = extentReports.startTest(testcasename);
		log.assignCategory(testname);
		extentReports.endTest(log);

	}
}

Create an ExtentReports object by specifying the result path where you want the report file to be stored. Make this as a configurable value so that it is easy to change it when its required.

Create an ExtentTest object to access the methods of Extent Reports.

createTestcase method would be assigning the test case name passed in argument and category. Then startTest method generates a toggle for the testcase name provided in the HTML report file and adds all the log events under this level.

This createTestcase method should be called in each test case class file so that a new level is created in the Report file.

Create a wrapper functions for all the assertions that are being done in the project by using the Extent Test methods. This will log all the assertions in the Report file. Below is a sample wrapper function for TestNG assertEquals method.

public void assertEquals(String actual, String expected, String message) {
		try {
			Assert.assertEquals(actual, expected, message);
			log.log(LogStatus.PASS, "PASS -- " + message);
		} 
		catch (AssertionError error) {
			log.log(LogStatus.FAIL, "FAIL -- " + message, error);
			throw new AssertionError();
		} 
		finally {
			extentReports.endTest(log);
			extentReports.flush();
		}
	}

 – log method will provide a capability to log different statuses present in LogStatus enum.

– endTest method prepares the test that has to be added to the Report file.

– flush method will append the report file with all the ended tests. If flush method is not called at the end then none of the ended tests will get appended to the HTML Report file.

The wrapper functions can be written for all TestNG assertion methods so that these assertions will be logged in the Report file.

Below are some of the snapshots of the sample Extent Report file.

Extent Reports Dashboard Page
Category Reports page
Test Case Report Page
October 2, 2020

4 responses on "Integration of Extent Reports to Test Automation Frameworks"

  1. Very nice article and very informative too, thanks for sharing

  2. Thanku so much… Very helpful

Leave a Message

Your email address will not be published. Required fields are marked *

© JSJR Solutions Private Limited 2018 All rights reserved.
WhatsApp us whatsapp