Saturday, October 27, 2018

How to implement ISuiteListener in TestNG?

ISuiteListener is an interface or TestNG listener provided by TestNG. This listener has two methods onStart() and onFinish(). onStart() method will be invoke before any test suite run and onFinish() method will be invoked after each test suite run.

So when we have a specific tasks that needs to be performed before running a test suite and after finishing the run then this listener will be helpful. Let us understand this listener with an example.

In this example we will be creating two child test suites and these will be executed from another test suite (parent).

Step 1: Create suiteListener() class to implement ISuiteListener() as shown below. Which will have onStart() and onFinish() methods implemented.
Step 2: Create two test classes say, suiteListenerTestClass1() and suiteListenerTestClass2() as shown below.

Step 3: Add each test class to a separate .xml file. suiteListenerTestClass1() to suite1.xml file and suiteListenerTestClass2() to suite2.xml file as shown below.

Step 4: Now create another .xml file say, suiteListener.xml to run suite1.xml and suite2.xml as shown below.

Step 5: Check the results below
The listener is invoke for each test suite. There are three suites suite1.xml, suite2.xml and suiteListener.xml for each of this test suite onStart() and onFinish() methods are invoked. This is how ISuiteListener works.

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

1 comment:

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...