How to use ScenarioStepContext in hook?

与世无争的帅哥 提交于 2020-01-06 06:11:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!