Icaroto
Icaroto

Reputation: 208

Specflow - How to use FeatureContext in BeforeFeature for Parallel Tests

to run tests in parallel you can't use the FeatureContext the way it is (eg: FeatureContext.Current.FeatureInfo.Title). So you have to inject it like the documentation states http://specflow.org/documentation/Parallel-Execution/

But, what if I'm using the FeatureContext in the [BeforeFeature] hook where it HAS to be a static method according to: https://github.com/techtalk/SpecFlow/wiki/Hooks

To exemplify I have this Hook that works fine when not running in parallel:

[BeforeFeature]
internal static void BeforeFeature()
{
// Some code here
string title = FeatureContext.Current.FeatureInfo.Title;
// More code here
}

How can I solve that?

Thanks!

Upvotes: 1

Views: 2804

Answers (1)

Andreas Willich
Andreas Willich

Reputation: 5825

With SpecFlow <= 2.1 this is not possible. With SpecFlow 2.2 we added the ability to get the FeatureContext as parameter. See this PR here https://github.com/techtalk/SpecFlow/pull/779

To use this now, you have to use a version from the CI- feed. A prerelease with it is planning for next week.

Upvotes: 2

Related Questions