Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolate class fields and properties in attribute-based step names #470

Open
delatrie opened this issue Mar 29, 2024 · 0 comments
Open
Labels
task:new feature Requesting new capability or software feature theme:core

Comments

@delatrie
Copy link
Contributor

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());
}
@delatrie delatrie added theme:core task:new feature Requesting new capability or software feature labels Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task:new feature Requesting new capability or software feature theme:core
Projects
None yet
Development

No branches or pull requests

1 participant