allure-framework / allure-framework/allure-csharp

Interpolate class fields and properties in attribute-based step names

Open
#470 0 comments 1 reaction 0 assignees View on GitHub
task:new feature theme:core
Dominant language
C#
Stars
125
Forks
76
Avg merge
1d 2h
Merged PRs (30d)
18

Description

### 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)
{

}

///
/// This property uniquely identifies the instances of the class
///
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());
}
```

Contributor guide

Open the contributing guide

Research direction

Start with AllureStepParameterHelper.GetStepName and AllureStepAspectBase, which the issue identifies as the relevant entry points. Trace how attribute-based step parameters are currently resolved, then define and test interpolation for instance properties and fields such as {this.NameThatIdentifiesThisClass}; done means the step name includes the instance value without breaking existing parameter interpolation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.