Simran Raina @sraina / 10.00 AM EDT. October 08, 2021.
Extent reports are the new industry standard way of sharing automation test reports. Not only do they look great but are also very easy to understand by a non technical person. Another feature is the plug and play nature of the set up. This blog will show you how to get an extent report up and running in no time.
When setting up an extent report, we most times ignore the the details of Extent Report dependencies; the hierarchy of the classes and the interfaces within the reporting jars. We mostly try to use code copied from somewhere and try to run it in our framework - sounds like you? Well there is nothing wrong with this approach. The only downside is you lose the ability to customize your report and create a more meaningful automation test report that fits the need of your web application.
I will quickly explain the different classes and remove the rocket science myth associated with using them. Let us dive in:
Your framework design should be simple and have these three things:
ExtentReport utility - used to define report template using ExtentHtmlReporter and report manager class ExtentReports. You also need the class ExtentTest to track individual tests in a single execution.
Listeners utility - used to listen to your tests and provide information to ExtentReport utility classes.
Test Case - used to execute the test method and verify the reporting framework.
To use ExtentHTMLReporter, ExtentReports and ExtentTest; you will need this dependency in your pom.xml:
<dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>3.1.5</version> </dependency>
To need a TestNG dependency to use Listeners. After setup, your project skeleton should look like this:
You will need a user-defined class ExtentReportDefinition to set up the name of the report and the location to store it in your project after the test execution has been completed and a report is generated. Then you will need to create an instance of the ExtentReports class which manages reporting and get inputs from the ExtentTest class which will collect individual test methods status from Listeners in the ExtentReportTestsTracker; another user-defined class in your framework.
Additionally, ExtentReportDefinition class will use ExtentHTMLReporter to configure the template instructions of the report. ExtentReportTestsTracker will be the class where the real action will be happening.
Next you will need three methods:
One for getting the start status of each test method from the Listeners utility.
Second, forgetting the execution status like Pass, Fail or Skipped status of the same test method that previously started.
Third for flushing the test as the test method finishes.
The start and finish information will be sent to ExtentReports class to insert the total execution time taken by the test method. Also, the Pass, Fail or Skip status will be sent to ExtentReports to show the test method status in the Report.
Now to understand the flow of execution, we can check out the below image: