Tuesday, 28 February 2017

Adding Extent Reports to generate the test reports

In software testing the main important part is reporting where user can able to get the status of any test cases. If we are running the test cases through TestNG or Junit, then we get some html reports which are not so good. To avoid the same, we can use XSLT reports which have the reports generated in PIE chart but we can’t get the complete information about the tests. For better understandings, we can keep the test logs & the status in a single html file & the same can be achieved by using Extent Reports.
Advantages of Extent Reports:
  • It can show the status of test cases in PIE chart.
  • Can add logs to each test cases.
  • Can show the user & system information in the report.
  • Can add screenshots in the report.
  • Can calculate the execution time.
  • Can be customized as per the requirement.

You can get more information about extent reports by following the below link: http://extentreports.com/docs/versions/3/java/           

To add extent reports in our project, make sure that you have added the below dependencies in pom.xml file:
              <dependency>
                     <groupId>com.relevantcodes</groupId>
                     <artifactId>extentreports</artifactId>
                     <version>2.40.1</version>
              </dependency>
  1.  Download ExtentManager.java & ReportsConfig.xml from here.
  2. Copy ExtentManager.java inside com.demo.pom.util package & ReportsConfig.xml inside src/test/resources.

Code Overview:
ReportsConfig.xml
This file contains all the required configuration for reports like The Title of the report, date format, reportnames etc. By using the parameters mentioned in this file the report will be generated. To generate the html report, we have a java class file known as ExtentManager.java. Let me explain the below code.

ExtentManager.java
In this class we have a static method getInstance(). The static method can be called directly by using the class name.
In the method 1st it will check whether the extent object is NULL or not. Initially when we call the getInstance() method the object should be null then it will create the report & will store the report inside the project’s report directory. The name of the file will be the current time stamp .html format.
Also, the report will take the parameters from the ReportsConfig.xml & generate the report as per the parameters mentioned inside ReportsConfig.xml.


By completing the above steps, we are ready to generate the extent reports. Please check the Next Post to check how can we use the extent reports in our test cases.



<<<Prev       Next>>>

No comments:

Post a Comment