Input your search keywords and press Enter.

How to create custom TestNG Report in Selenium with IReporter?

Custom TestNG Report Banner

Reporting is one of the key components of the Automation framework. Every automation framework should be implemented with test reporting which gives detailed data of the testing processes. The agenda of this tutorial is about creating a custom TestNG report based on its listener named IReporter. We have already discussed reporting in Selenium through Extent Reports and XSLT Report. I would like to recommend you tutorials on them.

Follow below links to learn reporting through Extent Reports and XSLT Report:

Some of the TestNG tutorials are-

If you have implemented TestNG as your test framework then you have the extra advantage of using TestNG report, so you can customize it as per your requirement with the help of its listeners.

How to find the TestNG Report in the project folder?

If you are using TestNG in your Selenium project, then after the first run of the TestNG class file a new folder named as test-output gets added to the project folder. You get emailable-report.html file, which is the default emailable report generated.

Here is the project hierarchy. If you don’t get the test-output folder then refresh your project.

TestNG Report Project explorer

 

Today we will learn to create a custom emailable report.

How to create customized TestNG report in Selenium?

We need to implement an IReporter interface to create a custom TestNG Report. So, if you implement IReporter by any Java class then you need to Override the unimplemented method as per the requirement to display data in the custom report, which is as below:

Steps to create custom TestNG HTML Report in Selenium

Here are the steps which you need to implement to create a custom HTML report in TestNG.

Step# 1: Implement IReporter and Override the unimplemented method

Above sample code has the unimplemented method. We will first take its second argument, that is, List<ISuite> suites. We will iterate through the ISuite which is basically iteration over the entire test suite.

Once we defined the iteration through for each loop then we put all the test results (consisting passed and failed tests) of the single suite inside the Map. We further get the key from the result map. This key will help further to find failed and passed tests.

We further use iteration over the keys and we identify the Context objects of the result.

Context help us further to get the map for failed or passed tests, which further gives their respective methods name.

Finally, we get custom details of the execution in the console and custom TestNG report as well.

Here is the implementation:

Step# 2: Create a Sample Test case

You should create a test case in TestNG class. Here is the sample program.

MySampleTest.java

Step# 3: Update testng.xml file with listeners

In the end, you need to add the IReporter implemented the class as a listener in your testng.xml file.

Finally run the testng,xml file and check your custom TestNG Report and console.

Console Output

Here is the console output which prints all the custom TestNG Report log.

TestNG Custom Report Console Data

How to find custom TestNG Report’s folder?

Now a new folder for custom TestNG Report will be added inside the test-output folder. Here we have a folder named Inviul Sample Test Suite, which is based on the suite name defined in the testng.xml file.

TestNG Custom Report Folder

When you click on this folder then you find your custom TestNG HTML report which has the name of the <test/> name which is written inside the testng.xml file.  Here is the custom TestNG Report.

TestNG Custom Report

Following image is the TestNG emailable report.

TestNG emailable report new

 

This is all about creating a custom TestNG Report in Selenium. If you have any queries then you can post in comment below, also don’t forget to subscribe to our Facebook group.

Join Inviul fb group

Avinash Mishra is the author of Inviul blog. He is a software engineer and blogger by choice. He loves to write blogs, and apart from blogging, he is interested in documentary film making, listening to music, traveling around the world and philanthropic activities.

Leave a Reply

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