allure-csharp
allure-csharp copied to clipboard
Interpolate class fields and properties in attribute-based step names
Discussed in https://github.com/orgs/allure-framework/discussions/2461
Originally posted by kiragengis March 30, 2024 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:
public class LogMore
{
[AllureStep("This method logs with more context when {parameter1} is identified within {this.NameThatIdentifiesThisClass}")]
public void ILogWithMoreContext(string parameter1)
{
}
/// <summary>
/// This property uniquely identifies the instances of the class
/// </summary>
public string NameThatIdentifiesThisClass { get; set; }
}
My approach would be to modify AllureStepParameterHelper.GetStepName to receive an instance from AllureStepAspectBase, and then add something similar to this to the if-else statement:
else if (TrySplit(pattern, '.', out var parts2) && parts2.Length == 2 && parts2[0] == "this")
{
// We probably need to do some validation around this line
stepName = stepName?.Replace(match.Value, instance?.GetType().GetProperty(parts2[1]).GetValue(instance).ToString());
}