Behat Scenario Hooks

Profile picture for user devraj

Scenario hooks are triggered before or after each scenario runs. These hooks are executed inside an initialized FeatureContext instance, so they are just plain FeatureContext instance methods.

There are two scenario hook types available:

@BeforeScenario: executed before every scenario in each feature. The @BeforeScenario hook executes not only before each scenario in each feature, but before each example row in the scenario outline. 

@AfterScenario: executed after every scenario in each feature.

/**
* @BeforeScenario
*/
public static function before()
{
    echo "Before Scenario Executed";
}

/**
 * @AfterScenario
*/
public static function after()
{
    echo "After Scenario Executed";
}

As per Behat official website, The background is run before each of your scenarios, but after your BeforeScenario Hooks.

Tags