0

I have a test, which fails in @AfterMethod annotation. When it happens, overrided onTestFailure() not called and not perform actions to attach screenshot to allure report. Is it possible to catch failures from @Before/AfterMethod or @Before/AfterClass in ITestListener or not?

Keker
  • 327
  • 1
  • 3
  • 13
  • 1
    Try to implement `org.testng.IConfigurationListener` `onConfigurationFailure` methods in advance. If you have some method like `attachScreenshotToAllure()`, you can insert its invocation for all _not-passed_ events in your Listener. – Max Daroshchanka Feb 01 '22 at 09:40
  • @MaxDaroshchanka Thank you, it works but with error - ERROR io.qameta.allure.AllureLifecycle - Could not add attachment: no test is running. Do you have any advices how to add attachment to not running test? – Keker Feb 01 '22 at 10:05
  • 1
    Now I see the issue more clear. Allure adds some specific since it has its own lifecycle. Seems you have to implement Allure lifecycle listener and override `afterTestStop` method. https://github.com/allure-framework/allure-java/blob/master/allure-java-commons/src/main/java/io/qameta/allure/listener/TestLifecycleListener.java and then apply your listener like this answer suggests https://stackoverflow.com/a/45693082/5226491. – Max Daroshchanka Feb 01 '22 at 10:58
  • 1
    See also this https://github.com/allure-framework/allure-java/issues/419#issuecomment-1015551798 – Max Daroshchanka Feb 01 '22 at 11:08
  • thank you for help, will check and return with result – Keker Feb 01 '22 at 12:57

0 Answers0