how to user test listener? some explanation and when we should use this?

please provide the sufficient answers,
and clear me with some fundamentals concept.

thank you


Default Asked on August 5, 2015 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Listeners wait for an event to happen so that we can perform some actions. For example, my requirement is that when ever a test fails, I want to re-execute it again 2 times until it passes. For this i’ll use listeners.

    Or you want to implement that onTestFailure or onTestPass print some statements:

    import org.testng.ITestResult;
    import org.testng.TestListenerAdapter;

    public class TestListeners extends TestListenerAdapter{

    public void onTestFailure(ITestResult tr){
    System.out.println(“Failing the Test -“+tr.getName());

    public void onTestSkipped(ITestResult tr){
    System.out.println(“Skipping the Test -“+tr.getName());

    public void onTestSuccess(ITestResult tr){
    System.out.println(“Passing the Test -“+tr.getName());

    Train Answered on August 6, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.