logo

The best IT Trainig Institute In Gurgaon

TestNG Listeners

Steps to Process the method
  • Create a new class in a common package and Name it for Eg:.Listeners
  • And then Write the Below code
package common;

import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class Listeners implements ITestListener{

	public void onTestStart(ITestResult result) {
		System.out.println("Test case is Starting");
	}
	public void onTestSuccess(ITestResult result) {
		
	}
	public void onTestFailure(ITestResult result) {
		System.out.println("Test Failed - Screenshot Captured");
	}
	public void onTestSkipped(ITestResult result) {
		
	}
	public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
		
	}
	public void onStart(ITestContext context) {
		
	}
	public void onFinish(ITestContext context) {
		
	}
}
              
  • And After writing this above code then Create a Test Suite
  • ANd Make change in that as given below code
< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
< suite name="Listeners test">
< listeners>
< listener class-name="common.Listeners" />
< /listeners>
  < test name="Functionl Testing">
  < parameter name="browser" value="Chrome">
    < classes>
      < class name="asc.groupTest"/>
    < /classes>
  < /test> 
< /suite> 
  • And Remember...! change the package and Class name in the test suite as per your class & package name
  • and Then Run the Code