问题
I am using SpecFlow with NUnit3 and am trying to access the step context within a hook.
I am running the tests in parallel so not using any static instance contexts, but using the parameter resolving feature of SpecFlow.
With a hook like below, the ScenarioContext instance resolves fine, but the ScenarioStepContext causes the binding to throw error:
Primitive types or structs cannot be resolved: TechTalk.SpecFlow.Bindings.StepDefinitionType (resolution path: TechTalk.SpecFlow.ScenarioStepContext->TechTalk.SpecFlow.StepInfo)'
[AfterStep]
public void LogStepResult(ScenarioStepContext scenarioStepContext,
ScenarioContext scenarioContext)
{
}
回答1:
Found it buried in some documentation...
Instead of trying to resolve the ScenarioStepContext
, you can use the ScenarioStepContext
that comes with the resolved ScenarioContext
in the StepContext property:
[AfterStep]
public void LogStepResult(ScenarioContext scenarioContext)
{
var stepContext = scenarioContext.StepContext;
}
回答2:
If you are not using parallel execution in your tests, then you can call ScenarioContext directly. Here is an example. If you are running tests in parallel, then you can use previous answer.
来源:https://stackoverflow.com/questions/50838738/how-to-use-scenariostepcontext-in-hook