Reputation: 208
I know is possible to get steps information from specflow by using ScenarioStepContext.Current.StepInfo
but this doesn't return if the step is inside the Background block or not.
Is there a way to find out if the Step inside the Background or the Scenario/Scenario Outline?
Thanks!
Upvotes: 0
Views: 405
Reputation: 5825
Currently there is no way to get this information in the StepInfo.
But there is a possible (but little hacky) way to get this information. You have to look at the StackTrace and search there for an method named FeatureBackground(). This is the method in the generated code, that comes from the background.
This code will do the job:
var stackTrace = new System.Diagnostics.StackTrace();
var stackFrames = stackTrace.GetFrames();
bool isBackground = stackFrames.Where(x => x.GetMethod().Name == "FeatureBackground").Any();
Upvotes: 1