Listeners
What are Listeners in TestNG : -
To say it in simple words, we can make TestNG to listen what we say with the help of Listeners. Listeners give us the flexibility to modify default TestNG's behaviors.
By using TestNG listeners 'ITestListener' or 'TestListenerAdapter' we can change the default behaviour write our own implementation when a Test fails or Skips etc.
We have extended TestListenerAdapter which intern implements ITestListener with empty methods. So again we don't have to override other methods from the ITestListener interface which we may not needed.
We will see the below list of methods in the example
OnTestStart : Invoked each time before a test will be invoked.
OnTestSuccess : Invoked each time a test succeeds.
OnTestFailure : Invoked each time a test fails
We can implement any logic that you want to do when a test fails
We can implement any logic that you want to do when a test fails
OnTestSkipped : Invoked each time a test is skipped.
OnTestFinish : Invoked after all the tests have run and all their Configuration methods have been called.
The below is the example program that demonstrates the Logging Listeners.
Testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TMS REGRESSSIONS" parallel="tests">
<listeners>
<listener class-name="ListeNers.CustomListener" />
</listeners>
<test name="TestC">
<classes>
<class name="ListeNers.LoginTest" />
</classes>
</test>
</suite>
steps:
1.Create a customListner class as shown in below programme.
2.CreateLogin test class which has all test that are need to be executed.
3.Tell testng about the listener using textng.xml--File is above
Comments
Post a Comment