Skip to main content

Behat Scenario Hooks

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.

Submitted by tgoswami on November 24, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.