What is Gherkin Language?
What are the primary keywords in Cucumber?
What do you mean by scenario in Cucumber Testing?
What are annotations in Cucumber?
What are hooks in Cucumber?
What is Cucumber Dry Run?
Why do we need to use Cucumber with Selenium?
How can you run Cucumber tests parallelly?
Hooks in Cucumber
Hooks are code blocks that execute before or after each Cucumber scenario in the execution cycle. This enables us to better control the development workflow and decrease code redundancy. Setting up the web driver and terminating the web driver session resembles a test setup. When dealing with different scenarios,
it's best to do the setup and clean up only once. Hooks are used to bringing optimization.
Certain preconditions, such as executing the program, creating a database connection,
preparing the test data, and so on, may be required in some cases. There are also several postconditions to be fulfilled, such as ending the database connection, closing the browser, refreshing test data, and logging out of the program.
Cucumber handles all of these situations with the use of hooks.