ITestListener/onTestFailure Not doing anything
See original GitHub issueTestNG Version
7.5
Expected behavior
ITestListener picks up failed tests and performs a screenshot. Previously worked on 7.4.0
Actual behavior
Test not being detected as failed, so inside methods not being ran.
Is the issue reproducible on runner?
- Shell
- Maven
- Gradle
- Ant
- Eclipse
- IntelliJ
- NetBeans
Test case sample
This code previous to 7.5 would run and perform the methods within. When I update to 7.5 the listener doesn’t seem to pick up the tests even though the listener is stated on every class. Has something changed?
Test classes are using Annotation @Listeners({TestListener.class})
package TestListeners;
import org.testng.ITestListener;
import org.testng.ITestResult;
public class TestListener1 implements ITestListener {
@Override
public void onTestFailure(ITestResult iTestResult){
System.out.println("Test has failed");
}
}
Test
package TestListeners;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners({TestListener1.class})
public class SimpleTestFailure {
@Test
public void sampleTest() {
throw new AssertionError("force fail");
}
}
Output:
java.lang.AssertionError: force fail
Issue Analytics
- State:
- Created 2 years ago
- Comments:11
Top Results From Across the Web
CustomListener's onTestFailure not ran when test fails
I am trying to get TestNG to do something when test fails using custom listener. I obtain TestNG instance with getDefault and I...
Read more >Attachment is not working when TestListener is in testng.xml
Attachment annotation and addAttachment helper method are not working when the TestListener class is added in testng.xml and not in a Test class ......
Read more >OnTestSucess is not working in TestNG Listeners
Hi Ashish,. I have already registered listener in testng.xml because onTestFailure is working fine only I found issue in onTestSuccess. Thanks.
Read more >Override onTestFailure - Google Groups
I'm having some trouble overriding a method "onTestFailure" from "TestListenerAdapter". ... Thks for the replay Cedric but its not working.. >.<
Read more >TestNG Listeners in Selenium: ITestListener & ITestResult ...
OnStart- OnStart method is called when any Test starts. ... onTestFailure- onTestFailure method is called on the failure of any Test.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@garyc0221 i can try taking a jab at it since I am a selenium literate.
Can you please create a sample project and attach it here which uses all the dependencies that your actual project has and which has a failing test along with a failure listener that takes screenshots?
Keep it as close to your actual project as possible so that we are looking at a replica of your actual project.
Yes can close this issue