Extent Reports: 5 Lines of code to set up reporting in Selenium

Top post on IndiBlogger, the biggest community of Indian Bloggers

Test reporting is one the important activity in quality assurance. It doesn’t matter whether you are a manual tester or automation tester, you must implement logging as well as reporting activities in your Automation framework. Extent reports give the seamless environment to implement test report generation in the Selenium project.

Extent reports efficiently support HTML reporting. It gives a broader view of the end results. Let’s discuss some of the advantages of using Extent Reports for test reporting in Selenium WebDriver.

Don’t Miss: How to set up Jenkins connection in Maven project for Selenium?

Advantages of reporting through Extent Reports:

  • It shows coverage in percentage
  • Pass – Failed report comes in pie chart format
  • A tabular format to display Pass, Fail and Skipped test step
  • Test environment details appear automatically in the Test report
  • Total tests and Total steps appear in the report
  • Total time taken for the current run as well as total time taken for the overall run appears in the report along with Start and end time count
  • Tests are configured and customized as per the choice of the test engineer/developer
  • Easy to implement this reporting in the Automation framework

Detailed Extent Reports

How to set up Extent Reports in IDE?

Firstly you need to add the library files of the Extent Reports. You can do it by uploading the external JARs to your project. Click here to download the JAR file.

If you are using Maven then add its dependencies to the pom.xml file.

How to implement Extent Reports in Selenium Automation framework?

As I claim above (in the title) that you only need 5 lines of code to implement the Extent reports, which is true as Sun rises in the east.

Here are the codes which you need to implement:

Starts with-

Ends with-

As you see above, you just need these five lines of code to implement Extent reports in your test automation framework. Let me explain the above code.

Step# 1: We create the instance of ExtentReports class and we pass arguments as path and file name with extension .html. As you see above, I have given the link to the path followed by file name as the current class name with .html as the extension.

Step# 2: Once the instance of ExtentReports created and path passed as the argument then we need to create the instance of ExtentTest. It holds the method which initiates and end the tests Along with the Log status as PASS, FAIL, SKIP, ERROR, FAIL, FATAL and WARNING.

Step# 3:  You need to implement the log status with the help of the instance of ExtentTest. You can implement it wherever you are asserting any condition as pass or fail. We will see it further in this tutorial.

Step# 4: At the end, you need to end the test along with flushing and closing of the report. It will help you to write the reporting to the designated file name.

Let’s discuss the implementation of Extent Reports in the execution of the test.

Scenario:  We are taking a scenario in which the driver will open the URL and it will capture the title at the home page. Now our task is to assert the title through the if-else statement. If the title contains the expected keyword, then Extent Reports should print this as pass. Similarly, if the title does not contain the keyword then Extent reports should print fail in the report generated.

Let’s have a look at the sample code:

Sample Code:

In the above code, you see the creation of the instance of both ExtentReports class and ExtentTest class are done inside @BeforeMethod annotation. Further, logging is done inside the @Test annotation. Ultimately, report closing and flushing are handled inside the @AfterMethod annotation.


One thing you should have noticed that there is a Boolean as another argument in ExtentReports() class. Right?

So, you may ask its significance here.

If we keep false then the single report will hold all the logs, otherwise on setting it to true will lead to the generation of multiple report file for every pass-fail status.

Extent Reports Dashboard

This is all about implementation of Extent Reports in your Selenium project. If you have any queries, please share in the comment below and join our Facebook group for the latest updates.

Join Inviul fb group


Leave a Reply