-
Notifications
You must be signed in to change notification settings - Fork 83
Hooks
The implementation you provide to any of the following hooks, will be called inside an implementation of selector inside an XCTestCase class. So you can safely create an instance of XCUIApplication for example.
You can have only have one before start hook that runs only once before executing any scenario.
beforeStart(^{
//Code that runs only once before running any scenario
});
You can have only one after hook that runs only after executing all the scenarios.
afterFinish(^{
//Code that runs only after finish executing all the scenarios
});
You can have as many before hooks as you want, each one will be executed before each scenario and they will be execut in First In First Out order.
before(^(CCIScenarioDefinition *scenario) {
//Code that runs before each scenario
});
You can have as many after hooks as you want, each one will be executed after each scenario and they will be execut in Last In First Out order.
after(^(CCIScenarioDefinition *scenario) {
//Code that runs after each scenario
//You can now check the scenario's success and failureReason properties
});
Exactly like your before hooks, with one exception; it will run only before the scenarios that has at least one of the tags you pass to this function.
beforeTagged(@[@"booking"], ^(CCIScenarioDefinition *scenario) {
//Code that will run before any scenario that has the tag @booking
});
Exactly like your after hooks, with one exception; it will run only after the scenarios that has at least one of the tags you pass to this function.
afterTagged(@[@"booking"], ^(CCIScenarioDefinition *scenario) {
//Code that will run after any scenario that has the tag @booking
});
Around hooks are a bit trickier than the rest. Around hook is responsible for firing the scenario execution. They are executed in First In First Out order. However, your scenario will be executed only once regardless of how many around hooks executing it. The first hook that matches a scenario, will have access to scenario execution block in order to fire it; any other matching, will go into a chain; so the last scenario fires the one before, till they reach the very first matching which will fire the scenario.
around(@[@"booking"], ^(CCIScenarioDefinition *scenario, void(^scenarioExecutionBlock)(void)) {
//Here you do whatever you want;
//Then you must call
scenarioExecutionBlock();
//Then you can continue doing whatever you want again :)
});