question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Attachments not working for Configuration Methods using IInvokedMethodListener (Allure-TestNG

See original GitHub issue

I’m submitting a …

- [X] bug report

  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

What is the current behavior?

Issue description:

  • I’m implementing the IInvokedMethodListener for TestNG
  • Inside it I have Overridden the afterInvocation method
  • I use this to create a log for the current test method Reporter.getOutput(testResult)
  • Then I try to attach this log file using this code Allure.addAttachment(attachmentDescription, "text/plain", attachmentContent, ".txt");
  • This works as expected for all @Test methods, but it doesn’t work for configuration methods like @BeforeMethod and @AfterMethod
  • This error is shown in the console [main] ERROR io.qameta.allure.AllureLifecycle - Could not add attachment: no test is running

Debugging Information

Upon debugging this issue I traced it to this method String io.qameta.allure.AllureLifecycle.prepareAttachment(String name, String type, String fileExtension)

Apparently threadContext.getCurrent(); is returning empty instead of returning the UUID of the current configuration method.

This behavior is shown if I’m running any test, but if I’m debugging it becomes intermittent, and sometimes works as expected!!!

What is the expected behavior?

The attachment should be added successfully, and this error should not happen.

What is the motivation / use case for changing the behavior?

This impacts reporting attachments for any configuration method.

Please tell us about your environment:

| Test framework | testng@7.0.0 | | Allure integration | allure-testng@2.13.1 | | AspectJ Weaver | aspectjweaver | 1.9.5 | | Java run-time environment | JDK | 13 | | IDE | Eclipse | Build id: 20191212-1212 |

Other information

  • I couldn’t downgrade to acpectj 1.8.0 because it’s not working with JDK 13
  • Tried using a different listener ‘IConfigurationListener’ but the same issue persisted

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
baevcommented, Jan 18, 2022

I can suggest using Allure Lifecycle listeners like io.qameta.allure.listener.StepLifecycleListener or io.qameta.allure.listener.TestLifecycleListener

1reaction
baevcommented, Jan 18, 2022

For me it’s working randomly once it’s adding attachments, once it’s not…

yeah, that’s because Allure is using the same API to process TestNG lifecycle events, and there is no guarantee in what order this hooks are executed. So basically if your hook goes first, you’ll see the attachment in the report, otherwise you’ll not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attachments not working for Configuration Methods using ...
I'm implementing the IInvokedMethodListener for TestNG; Inside it I have Overridden the afterInvocation method; I use this to create a log for ...
Read more >
TestNG adapter incorrectly places @AfterMethod in report
It's problem of TestNG adaptor. In our adaptor we use ITestListener listener and onTestSuccess , onTestFailure , onTestFailedButWithinSuccessPercentage and ...
Read more >
allure-framework/allure-core - Gitter
Mail body is empty and It's not opening another system. I want to attach static allure report to JIRA and anyone want to...
Read more >
TestNG Listeners in Selenium : Types & Examples
Read about different types of TestNG listeners with examples and code ... The TestNG class contains different configuration methods.
Read more >
Custom TestNG Listeners using IInvokedMethodListener
IInvokedMethodListener allows user to perform certain action before/after a method has been executed - something like clean up or setup.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found