Skip to content
Ahmed Ali edited this page Jan 25, 2016 · 3 revisions

Dev

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.

Before Start

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
    });

After Finish

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
    });

Before

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
    });

After

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
    });

Before Tagged

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
    });

After Tagged

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

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 :)
    });