IInvokedMethod Listener performs some tasks before and after the methods execute. We generally use it for setting up configurations or cleanup etc.
IInvokeListener invokes before and after every test method available in the test code, unlike ITestListener. The IInvokedMethod listener contains two methods:
- beforeInvocation(): This method invokes before every method.
- afterInvocation(): This method is invoked after every method.
Code example:
package IInvokedMethod;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
public class ListenerTestNG implements IInvokedMethodListener{
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
// TODO Auto-generated method stub
System.out.println("This is my listener beforeInvocation logs : "+method.getTestMethod().getMethodName()+ " "
+ " of the class " +testResult.getTestClass());
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
// TODO Auto-generated method stub
System.out.println("This is my listener afterInvocation logs : "+method.getTestMethod().getMethodName()+ " "
+ " of the class " +testResult.getTestClass());
}
}
Follow the process to implement the IInvokedMethod Listeners in TestNG
Comments
Post a Comment