allure-framework / allure-framework/allure-csharp
Allow modifying previous steps, or make step context active during Reqnroll BeforeStep hook
- Dominant language
- C#
- Stars
- 125
- Forks
- 76
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 18
Description
This is part feature request, part bug report.
I have a Reqnroll/Selenium project where I'd like to take screenshots of the browser before each step of the test, but only attach them to the corresponding steps if the test fails. As far as I can tell, Allure doesn't (intentionally) allow adding attachments to steps that have already finished. So far I've been working around this by calling `AllureLifecycle.Instance.UpdateStep`, saving a reference to the step, and then, if the test fails, calling `UpdateStep` again later (to lock the internal mutex) but instead adding the attachment to the step reference that was saved earlier.
As of updating to Reqnroll 3 and Allure.Reqnroll 2.15.0, this no longer works, as I save the references in the `BeforeStep` Reqnroll hook, and detect errors and attach screenshots in the `AfterReqnroll` hook, and it seems that Allure no longer counts these hooks as being part of the step (I get a "no step context is active" error).
I know this is very much a hack and is probably not supported. However, this also means that any attachments added (normally, using `AllureApi.AddAttachment`) during the `BeforeStep` or `AfterStep` hooks get added to the entire test and not to the step associated with the hook, which seems like incorrect behavior.
So, the bug is that Allure no longer considers Reqnroll's `BeforeStep` and `AfterStep` hooks to be part of the step. The feature request is that I would like to be able to (in a more supported way) add attachments to steps that have already completed, either by saving a reference, or by name, or by indexing into a list of steps, it doesn't really matter.
Here is a code example to demonstrate:
```csharp
[Binding]
public class Hooks
{
[BeforeStep]
public void AllureBeforeStep()
{
// This line will error because no step context is active
AllureLifecycle.Instance.UpdateStep(step => step.name = "foo");
// Commenting out the above line and running again shows that this attachment
// gets added to the entire test, not the step the hook should be associated with
AllureApi.AddAttachment("text", "text/plain", Encoding.ASCII.GetBytes("foo"), "txt");
}
}
```
Contributor guide
Research direction
Start with the Reqnroll BeforeStep and AfterStep integration, then trace AllureLifecycle.UpdateStep and AllureApi.AddAttachment using the supplied Hooks example. Confirm how step context is handled during hooks and after steps. Done means the intended hook attachments target their associated steps, or a documented supported way exists to modify completed steps, with coverage for the reported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100