Skip to content

Allow modifying previous steps, or make step context active during Reqnroll BeforeStep hook #655

@keegan-conlee-IM

Description

@keegan-conlee-IM

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:

[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");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions