Adding Hooks to Cucumber code

After finding out how to run a few selective Features, the next great thing is running some code before or after test Scenarios. These are very basic and desired Features for Test Automation Frameworks. Examples of this could be initializing the browser before the execution starts and closing the browser after the execution is complete. So how do we do this in Cucumber? Let's take a look at this in this recipe.

Getting ready

For this recipe, we are going to update the home_page.feature file to the one shown as follows:

Feature: Home Page Background: flow till home page Given user is on Application home page @sanity @wip Scenario: Home Page Default content Then user gets a GitHub Bootcamp section @regression @wip Scenario: ...

Get Cucumber Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.