Introduction
What are Hooks
Types of Hooks
The names are intuitive
- Beforetestrun and aftertestrun represents the code that will be executed before and after all tests
- Beforefeature and afterfeature represents the code that will be executed before and after every feature
- Beforescenario and afterscenarion represents the code that will be executed before and after every scenario inside a feature
- Beforescenarioblock and afterscnearioblock represents the code that will be executed before and after every scenario block
To be more precise, below you can see an example of a scenario with 3 blocks. The test will be executed before and after Given/When/Then blocks
- Beforescenariostep and afterscneariostep represents the code that will be executed before and after every scenario step
Creating Hooks File
A default class is created:
Modify this class and add all hooks you need.
Restrict Hook Execution with Tag Filtering
The code below from you hook file will be executed for those scenarios tagged with @Login and @forgotPassword (when we are in if)
Want to lean more about BDD? Have a look on this book: BDD in Action: Behavior-driven development for the whole software lifecycle
Happy testing and... make it green, becomes a dream :).
No comments:
Post a Comment