How ITestListener TestNg Listener Works Selenium Example Program?

ITestListener TestNg Listener Implement in Selenium: How ITestListener TestNg Listener Works Selenium Example Program?

ITestListener TestNg Listener

ListenerMain With Itestlistener

package com.selenium.TestNG;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
public class ListenerMain implements ITestListener
{
   @Override
   public void onFinish(ITestContext Result) 
   {	
      System.out.println("Test Casse Is Finished"+Result.getName());
   }
   @Override
   public void onStart(ITestContext Result) 
   {
      System.out.println("Test Casse Is Started"+Result.getName());	
   }
   @Override
   public void onTestFailedButWithinSuccessPercentage(ITestResult Result) 
   {
      System.out.println("Test Casse Is FailedwithSucesspercentage"+Result.getName());	
   }
   @Override
   public void onTestFailure(ITestResult Result) 
   {
      System.out.println("Test Casse Is Failed"+Result.getName());	
   }
   @Override
   public void onTestSkipped(ITestResult Result) 
   {
      System.out.println("Test Casse Is Skipped"+Result.getName());
   }

   @Override
   public void onTestStart(ITestResult Result) 
   {
      System.out.println("Test Casse Is Started on Test"+Result.getName());
   }

   @Override
   public void onTestSuccess(ITestResult Result) 
   {
      System.out.println("Test Casse Is Sucess"+Result.getName());		
   }
}
package com.selenium.TestNG;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners(com.selenium.TestNG.ListenerMain.class)
public class Listener_TestlistenerEx 
{
   @Test
   public void login() throws InterruptedException
   {
      WebDriver driver=new FirefoxDriver();
      driver.get("http://www.google.com");
      Thread.sleep(5000);
      driver.close();
   }
}

Avatar for Softwaretestingo Editorial Board

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

Leave a Comment