Integration of Extent Reports to Test Automation Frameworks
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.
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.
– 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.
Very nice article and very informative too, thanks for sharing
Thank you Divya
Thanku so much… Very helpful
Thank you Mahi