Selenium WebDriver Framework: Report Module

This is Part 3 of the Selenium WebDriver Framework Series and in this post, we add the Report Module to the framework. Each of the operations or steps will be logged/written onto the result html file using ExtentReports library.


What we want?

  • Each step should be automatically logged to the result html file
  • Screenshots should be taken and added to the result in case of failure
  • A proper interactive HTML report for each executions

For the third point, we will be using ExtentReports library. I hadn’t used this before and decided to try it out for this tutorial series.

So lets start!

Framework Report Module

The report related classes will be maintained in ‘’ package. Take a look at the completed package structure.


Since we are using ExtentReport for our reporting and we do not want it to be closely coupled with our framework, we use the IExecutionReporter interface and get the ExtentReport implementation using the Reporter factory.

In more detail, we have the IExecutionReporter interface which has the methods for logging the steps along with methods to define test start and finish.

Reporting using ExtentReporter class

The ExtentReporter class implements the above interface and provides the ExtentReport library implementation. Lets take a look at a few examples.

  • ExtentReport object is initialized providing the file path for the result html as shown below. In our case, the initialization is done inside the ReporterFactory class.
  • Once its initialized, we have to ExtentTest object for each test. This is done in our overriden startTest method.
  • The steps are entered using the log methods as follows.
SEE ALSO:   8 Reasons to Save your Automation Results in Database
  • As you might have guessed, ExecutionStatus is an enum for storing the execution result status.
  • In case of error, the screenshot will be taken by ExecutionListener class and will be added to the HTML report.
  • There is a feature to assign category in ExtentReports and we can map the groups in TestNG to categories
  • After completing the test, we have end the test as shown
  • After all the tests are completed, the extend object is closed and flushed to generate the HTML report
This ExtendReporter object will be used by ExecutionListener class which is aTestNG listener.

SEE ALSO:   Upload Files using Selenium WebDriver


ExecutionListener extends TestListenerAdapter and does the reporting of test start, finish, failure, success etc.

  • The constructor to this class accepts the IExecutionReporter object (our ExtentReport implementation) and uses it to report the events.
  • Take a look at the onTestStart and onTestSuccess methods. In the test start, we starts the ExtentReport test and assigns the test groups as categories. On test success, the success message is logged
  • In case of failure, we take the screenshot and report it.
Now that we have seen the listeners and reporters, lets take a look at how its been used.


  • The ReporterFactory generates the ExecutionListerner instance by passing in the ExtentReports object.
SEE ALSO:   How to Take Different Types of Screenshots in Selenium WebDriver
At this point in the tutorial, we have a RunTestNG class which holds the above code. Here we have to find a means to add the test classes to the TestNG object in order to execute them.

We will cover that in the next article.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *