Add an instance variable to the Step Name #2461
kiragengis
started this conversation in
Ideas & Feedback
Replies: 1 comment 1 reply
-
Hi again, @kiragengis ! I've created a feature request from this discussion: allure-framework/allure-csharp#470. Feel free to open a PR on that matter. Until it's implemented, however, the solution below should work. You can bypass [Injection(typeof(RenameAspect), Priority = 0)]
[Injection(typeof(Allure.Net.Commons.Steps.AllureStepAspectBase), Priority = 1)]
public class StepWithPropertiesAttribute : AllureStepAttribute
{
public string? NamePattern { get; }
public StepWithScreenshotAttribute(string? name = null) : base(null)
{
this.NamePattern = name;
}
} The public class RenameAspect
{
/* ... */
void UpdateStepName(object? instance, MethodBase metadata)
{
var pattern = metadata.GetCustomAttribute<StepWithPropertiesAttribute>().NamePattern
if (instance is not null)
{
// Insert instance fields/properties here.
// You may optionally use FormatFunctions.Format with AllureLifecycle.Instance.TypeFormatters.
pattern = "...";
}
// Call GetStepName to insert parameters.
var name = AllureStepParameterHelper.GetStepName(
pattern,
metadata,
args,
AllureLifecycle.Instance.TypeFormatters
);
AllureApi.SetStepName(name);
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To give more context to the step, I want to be able to refer to a property value of the class in the step name. This is an example:
My approach would be to modify
AllureStepParameterHelper.GetStepName
to receive an instance fromAllureStepAspectBase
, and then add something similar to this to the if-else statement:Beta Was this translation helpful? Give feedback.
All reactions