问题
I am having trouble adding the ability to call the feature and scenario contexts when running the framework in parallel.
I have looked over
http://specflow.org/documentation/Parallel-Execution/
but I am still having trouble understanding how to actually add this to the framework.
Does anyone have an example of this working in practice?
I am trying to create a report using
ParentNode = Extent.CreateTest(FeatureContext.Current.FeatureInfo.Title);
but I cant call this when running in parallel, any help on getting this thread safe will be extremely welcome
回答1:
In simple terms you cannot call FeatureContext.Current
or ScenarioContext.Current
in parallel.
instead ask for an instance of either FeatureContext
or ScenarioContext
in the constructor of the steps class that you want to use it in, and Specflows DI container will give you the current one for the currently executing test, and you can then store that as a field in your class and use that field safely.
来源:https://stackoverflow.com/questions/48586809/threadsafe-scenario-feature-context