Can I replace a step attachment if it has the same file name? #3070
Unanswered
kunalashar25
asked this question in
Questions & Support
Replies: 1 comment
-
Hi, @kunalashar25 You may post-process the step result in an [Binding]
public static class Hooks
{
[AfterStep]
public static void DeduplicateAttachments()
{
AllureLifecycle.Instance.UpdateStep(s =>
{
var uniqueAttachments = new HashSet<string>();
s.attachments = s.attachments.Reverse<Attachment>().Where(a =>
{
if (uniqueAttachments.Contains(a.name))
{
return false;
}
uniqueAttachments.Add(a.name);
return true;
}).Reverse().ToList();
});
}
} The hook above keeps the most recently added attachments. If you prefer keeping the earliest ones, remove two Another option would be to wrap each attempt in a sub-step, but that may require execution context manipulations, which makes the task trickier and also depends on how exactly you run retries. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Reqnroll with Allure and attaching JSON at the step level. Some steps have retry logic (if assertion fails), and when retried, the same file gets attached multiple times. Is there a way to replace the attachment if it has the same file name, instead of adding it again?
Image for reference

Beta Was this translation helpful? Give feedback.
All reactions