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
TestNG 7.5 cannot add attachments to test upon failure #707
Describe the bug
When using TestNG 7.5 with allure 2.17.2 & 2.17.3 trying to add attachments to tests once they failed does not work and generates an error.
To Reproduce
Steps to reproduce the behavior:
Have a project setup with selenium, testng and allure
Create a test listener for failure and save screenshot
Run a test that fails
See error
Expected behavior
The attachment should save and be added to the allure report - this can be done by going back to TestNG version 7.4.0
Screenshots
Desktop (please complete the following information):
I have same problem with Allure 2.17.3 and TestNG 7.5.
Allure saves screenshot into allure-results folder, but doesn't attach it to generated report cause test-result.json file has empty attachment field.
Works fine with TestNG 7.4.0.
Have the same problem when was updated to TestNG 7.5,
i was debugging there is prepareAttachment method in AllureLifecycle, and after switch to TestNG 7.5 thereadContext.getCurrent(); returns Optional.empty
And one more thing, looks like Flaky tests are not marked as Flaky in Allure report
I ran into the same issue. I have came up with a solution which relies on Allure lifecycles instead of TestNG lifecycles. I would consider it better since I want to use an Allure feature and I don't want it to be that heavily dependent on TestNG.
I had to rework my listener so it is implementing Allure's TestLifecycleListener, and I had to register it with SPI, which is just a tiny bit more complicated than putting on annotation with TestNG.
I have created a short, basic and rough example repository based on @garyc0221 example code in the thread to show what it takes to use Allure lifecycle instead.
Reacted by garyc0221, Dmitry Mayer, AlexChernookov and Dmitrii Rysak
If the only way to get all the execution data is to use the same API that users will use to control tests execution (such as creating failure screenshots etc) and no way to change the ordering is provided, there aren't much we can do with it
Activity
garyc0221 commentedon Jan 17, 2022
Actually looks like allure has a lot of things broken by TestNG 7.5
garyc0221 commentedon Jan 17, 2022
Example test listener class
Example test which passed with TestNG 7.40 but not 7.5
vkhromenkov commentedon Mar 1, 2022
I have same problem with Allure 2.17.3 and TestNG 7.5.
Allure saves screenshot into allure-results folder, but doesn't attach it to generated report cause test-result.json file has empty attachment field.
Works fine with TestNG 7.4.0.
AlexChernookov commentedon Mar 2, 2022
Have the same problem when was updated to TestNG 7.5,
i was debugging there is prepareAttachment method in AllureLifecycle, and after switch to TestNG 7.5 thereadContext.getCurrent(); returns Optional.empty
And one more thing, looks like Flaky tests are not marked as Flaky in Allure report
Are there any workarounds ?
garyc0221 commentedon Mar 2, 2022
@AlexChernookov
I have found no workarounds, I had to downgrade the TestNG version to 7.4.0 to work with allure 2.17.3
For the flaky tests, they are working for me with 7.4.0 just by annotating tests with @flaky like this. MIght be broken using 7.5 only
AlexChernookov commentedon Mar 2, 2022
@garyc0221
So the best workaround now is to downgrade TestNg to 7.4.0. Hope that issue with 7.5 will be fixed in next releases
biczomate commentedon Mar 12, 2022
Hello!
I ran into the same issue. I have came up with a solution which relies on Allure lifecycles instead of TestNG lifecycles. I would consider it better since I want to use an Allure feature and I don't want it to be that heavily dependent on TestNG.
I had to rework my listener so it is implementing Allure's TestLifecycleListener, and I had to register it with SPI, which is just a tiny bit more complicated than putting on annotation with TestNG.
I have created a short, basic and rough example repository based on @garyc0221 example code in the thread to show what it takes to use Allure lifecycle instead.
garyc0221 commentedon Mar 14, 2022
@biczomate This is amazing thanks, did not know allure had its own test listener. Works flawlessly.
iRaunchy commentedon Mar 30, 2022
@biczomate Amazing!
But the proper fix would be nice from Allure team.
baev commentedon Mar 30, 2022
I'd say https://github.com/biczomate/allure-testng7.5-attachment-example is the way to go. Issues with listeners order are the main reason AllureLifecycleListener was created in the first place.
If the only way to get all the execution data is to use the same API that users will use to control tests execution (such as creating failure screenshots etc) and no way to change the ordering is provided, there aren't much we can do with it
garyc0221 commentedon Apr 1, 2022
Going to close this issue as https://github.com/biczomate/allure-testng7.5-attachment-example is the way to go. With Allure listener, you don't even need to define the listener within each test class, which is nice.
[#1] Registration and login tests