BeforeScenarioBlock to execute just before the "Given" expression
Based on the SpecFlow documentation , the hook [BeforeScenarioBlock]
will be called before the "Given" and "When" statements. Is there a way to make a [BeforeScenarioBlock]
call-only hook before the "Given" statement?
source to share
[BeforeScenarioBlock]
will be executed before any "block" in the script, that is, before each separate set of blocks Given
, When
or Then
. There is no built-in way to specify that the hook should only run before a specific block type, I don't think so, but I think it should be simple enough to make sure the code is only executed before specific blocks within the hook code. Like that:
[BeforeScenarioBlock]
public void BeforeScenarioBlock()
{
if (ScenarioContext.Current.CurrentScenarioBlock == ScenarioBlock.Given)
{
//execute the code before the given
}
}
I haven't tested it though.
source to share