Saturday, October 27, 2018

How to implement IExecutionListener in TestNG?

IExecutionListener is an interface or TestNG Listener provided by TestNG. This listener monitors the beginning and ending of the TestNG execution.

IExecutionListener interface has two methods onExecutionStart() and onExecutionEnd(). onExecutionStart() will be invoked before TestNG execute any test suite and onExecutionEnd() will be invoked after TestNG executes all test suites.

Let us understand this with an example:

Step 1: Create a executionListener() java class and implement IExecutionListener to it as shown below.
Step 2: Create test class like executionListenerTestClass() and some test methods. Also add configuration methods which will be executed before and after test suite execution as shown below

Step 3: Create a testng.xml file (executeListener.xml here) and associate the listener class with test class by adding <Listener> tag as shown below.
Step 4: Execute executeListener.xml as TestNG suite and see the results in the below screenshot


From the above results it is clear that onExecutionStart() method is executed before any suite execution and onExecutionEnd() method is executed after test suite.

This listener can be used for opening and closing Database connection, deleting cookies and third party tool integrations in real time Selenium automation projects.

Please comment your queries or suggestions on this post. Thanks for reading. #HappyLearning #HappyTesting #QABABU

1 comment:

  1. Thanks you for sharing the article. The data that you provided in the blog is infromative and effectve. Through you blog I gained so much knowledge. Also check my collection at selenium Online Training Blog

    ReplyDelete

Katalon 08: Integration of HP ALM with Katalon Studio

In this post, this post we discuss about integration of  HP ALM with Katalon Studio. If we can integrate HP ALM with Katalon we can update ...