Listeners

Home >> Tags >> Listeners

Extent Reports using TestNG Listeners in POM

As we know all know that ExtentReport is an HTML reporting library (open source) which can be integrated with Selenium WebDriver.

In this article, we will teach you how to develop advanced extent reports / integrate Extent Reports with your existing test automation framework.

We assume you have a working knowledge on Selenium,TestNG and Maven.

Let us start now !!!!

Importance of Reporting in a Test Automation Framework :-

IMethodInterceptor examples to reorder list of test methods

IMethodInterceptor is used to alter/modify the list of test methods to be executed by TestNG.

When we implement IMethodInterceptor interface which has just one method to implement 'intercept(java.util.List methods, ITestContext context)', using this method we can reorder the list of test methods and return List of IMethodInstance which TestNG runs. TestNG will now run these test methods in the same order which is found in the returned list.

Listeners in JMeter

Listeners facilitates viewers to view responses generated by samplers in the form of tables, graphs, trees or simple text in some log files and also give pictorial access to the data collected by JMeter about those test cases as a Sampler component of JMeter is executed.

To view the details of sampler requests and responses, add either "View Results Tree" or "View Results in table" Listeners to a test plan which displays basic HTML and XML representations of the response. To view the response time graphically, add Graph Results which plots the response times on a graph.

Customize TestNG html Report

Please visit for the updated article customized emailable report along with screenshots which works perfect for newer versions of testNG and tested with testng latest version 6.14.3

When ever we execute tests with TestNG, it will generate a default html report with basic information.

Webdriver Event Listener example

Webdriver events are helpful to view the events triggered by webdriver. It also plays an important role in analyzing results and helps us in debugging issues if we encounter any.

Selenium webdriver has ability to track different events such as 'beforeNavigateTo' , 'afterNavigateTo' , 'beforeClickOn' , 'afterClickOn', 'onException' and so on. When ever we develop test scripts we can write our own implementation for handling events during the execution.

Take Screenshot and place it in a folder with Test Class name

In this tutorial, we will see taking a screen shot with test name and placing it in a folder by creating a folder with Test Class Name.

As we are taking screen shots on failure, we need to add logic in creating a screen shot and naming it with test name and place it in its test class name respectively.

We can get the test class name using 'result.getInstanceName()'. Test class name looks some thing like "com.pack.sample.HomePage". But we need to create a folder name with test class name i.e 'HomePage'.

Logging with TestNG using Listeners

In TestNG we can generate logs with the help of Listeners. Listeners implement the interface "org.testng.ITestListener". There are methods which gives you a real time information.

You can either extend 'TestListenerAdapter' or implement Interface 'ITestListener' which is a listener for test running.

What are Listeners in TestNG : -