Selenium WebDriver - TestNG @Listener Annotations

4:18 AM 4 Comments

@Listeners Annotations in TestNG


A simple ITestListener adapter that stores all the tests that were run. You can retrieve these results with the following methods: getPassedTests() getFailedTests() getSkippedTests().
In addition to that we can reuse the existing methods like onTestSuccess(ITestResult tr),onTestSkipped(ITestResult tr) and onTestFailure(ITestResult tr) of org.testng.TestListenerAdapter Class.
If you extend this class in order to override any of these methods, remember to call their super equivalent if you want this list of tests to be maintained.

Implementation of TestListener Adapter Class

Steps to use TestListener Adapter class

1. First extend the TestListenerAdapterClass.
Example:
public class useListeners extends TestListenerAdapter
2. After that over the methods of onTestSuccess(ITestResult tr),onTestSkipped(ITestResult tr) and onTestFailure(ITestResult tr) in the useListeners class.
3. Use @Listener annotation in the Test Class which contains @Test Annotations.
4. Execute the Test Class using testng.xml or run an Testng Test.
5. For every @Test methods available in the Test Class based on the status of pass/fail/skipped the Listener methods are called.

Unknown

This site creates a platform to become an expert by gaining knowledge of unknown real-time issues as well.

4 comments:


Well did here, a set of useful interview questions which looks really helpful a lot to learn about the subject and also during interviews. But now a days Manual testing is not so enough to get placed in MNC companies, hence here I like to share some the most trending area in software testing field, which is Selenium -- A Top trending automation testing tool. Learn more about Selenium here ==> Best Selenium Training Institute in Chennai
FREE PDF download the course content ==>
Selenium Training in Velachery

Priya Kannan said...

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
Selenium Training in Chennai

likitha said...

Great step by step solution, thanks for the help!
selenium Online Training Hyderabad