You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Attachment is not working when TestListener is in testng.xml #444
Attachment annotation and addAttachment helper method are not working when the TestListener class is added in testng.xml and not in a Test class - i.e.
Attachment works when this is added in each Test class: @Listeners({base.TestListener.class})
Attachment does not work when this is added in testng.xml:
Thats because of TestNG listeners order. Allure TestNG integration implements listener as well, so if Allure listener invoked first you'll get no attachment (as Allure test context will be closed before your custom listener execution). As far as I know there is no guarantee on listeners order for TestNG.
At this point I can suggest you to use Allure Lifecycle listeners
TestLifecycleListener.beforeTestStop hook will be invoked for each test result just before Allure context closes. So you'll be able to check the status of result and in case of failure add screenshot to it.
Thanks for this prompt response. While I managed to implement the Allure TestLifecycleListener I can't seem to get the instance of my BaseTest that contains the WebDriver and therefore I can't take screenshot. Any idea how I can accomplish this as there is no getInstance() in io.qameta.allure.model.TestResult.
In the screenshot above of Debug view, it was mentioned in Labels the testClass involved but it returns a string.
Activity
baev commentedon May 22, 2020
Thats because of TestNG listeners order. Allure TestNG integration implements listener as well, so if Allure listener invoked first you'll get no attachment (as Allure test context will be closed before your custom listener execution). As far as I know there is no guarantee on listeners order for TestNG.
At this point I can suggest you to use Allure Lifecycle listeners
https://github.com/allure-framework/allure-java/tree/master/allure-java-commons/src/main/java/io/qameta/allure/listener
https://github.com/allure-framework/allure-java/blob/master/allure-java-commons/src/main/java/io/qameta/allure/listener/TestLifecycleListener.java
TestLifecycleListener.beforeTestStophook will be invoked for each test result just before Allure context closes. So you'll be able to check the status of result and in case of failure add screenshot to it.PS Allure listeners can be added via Java SPI
works-of-nestor commentedon May 23, 2020
Thanks for this prompt response. While I managed to implement the Allure TestLifecycleListener I can't seem to get the instance of my BaseTest that contains the WebDriver and therefore I can't take screenshot. Any idea how I can accomplish this as there is no
getInstance()inio.qameta.allure.model.TestResult.In the screenshot above of Debug view, it was mentioned in Labels the testClass involved but it returns a string.
baev commentedon May 23, 2020
the best option would be to use ThreadLocal to store reference to WebDriver
works-of-nestor commentedon May 24, 2020
I was able to attach screenshot now using ThreadLocal. Thank you.
ZuhayrMerchant110 commentedon Aug 9, 2023
Can you guid me that how you use ThreadLocal to store current test's driver to get the screenshot? @works-of-nestor