top of page
Search

How to Generate a Plug and Play Extent Report

Simran Raina @sraina / 10.00 AM EDT. October 08, 2021.


How to Generate Plug and Play Extent Reporting

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:


Test Method will be executed and start will be listened to by the Listener utility. The same will be notified to ExtentTestsTracker by invoking the start() method. A random unique id will be created to track this test method as there could be multiple parallel test methods running in a single execution. This unique id will help track the individual test methods and their lifecycle from start -> pass/fail/skip -> finish. The entire sequence will be reported to the ExtentReports class, which will generate the whole report.


Listener and ExtentTestsTracker will be communicate back and forth for each test method and start(), pass(), fail(), skip(), finish() methods in Listener will bind the call to respective start(), getStatus(), finish() methods of ExtentTestTracker.


At this point, it is now time to write our test methods. Let us add two test methods. One will be a pass while the other fail to enable you see both scenarios in your test report.

You can download all the code of this blog from BusyQA GitHub Public Repository


After execution, your console will look like this:


A TestReport folder will be created. Refresh your project to view the HTML report inside the TestReport.



Finally, go to the report file location and open the report. Viola, you will see your automation customized report ready to be shared with your boss.


At BusyQA, our Automation training and in house coop program has launched the careers of many Automation Engineers. We are passionate about automation testing technology. Reach out and enroll in our CI Automation course offerings to learn more from me in a live classroom environment. I hope this was helpful.


Happy Thanksgiving!





bottom of page