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: GitHub Bootcamp Section When user focuses on GitHub Bootcamp Section Then user gets an option to setup git
How to do it…
- In the
automation
package, create one java classHooks.java
and put the following...