Skip to content

Scenario

Ahmed Ali edited this page Jan 24, 2016 · 8 revisions

##@Everyone

Scenario

A scenario defines a set of steps in a specific order and your app is supposed to be able to perform these steps. Any step that fails, the whole scenario considered to be failed. When such a failure happens, Cucumberish will instruct Xcode to highlight the step that failed in your .feature file and show you a message that clarify why this step failed.

Example:

Scenario: Eat pizza
    Given there is enough slices for 1 person
    When I eat 2 slices
    Then I should have 1 slice remaining

#Scenario Outline Sometime you will find yourself repeating the same scenario inside the same feature for several times in order to achieve a specific result.

Let's say in order to invite a friend you have to go through a specific number of steps. So what happens if you want to invite 5 friends one per time?

For such situations you will find the Scenario outline a very handy way to do it. Here is how you would write a scenario outline:

Scenario Outline: Invite a friend
    Given I am logged in as "Ahmed"
    And I am on "home" screen
    When I tap "invite" button
    Then I write "<FriendEmail>" into the "Email" field
    And I write "<FriendName>" into the "Name" field
    And I tap "Invite Friend" button
    Then I should see "<FriendName> Invited" message

As you can see, some steps in the outline have placeholders instead of real values;

However, a scenario outline on its own does nothing; it is just an outline. It needs example data in order to run. This takes us to the next point.

#Examples

In order to get your scenario outline to run you provide the examples as the following

Examples:
    | FriendName | FriendEmail |
    |  Friend 1  |   Email 1   |
    |  Friend 2  |   Email 2   |
    |  Friend 3  |   Email 3   |

The first row in the examples table, defines the variable name s All the rows after the first one defines the values that will be used. For the above example, the scenario outline will be executed 3 times; where the first time the "" will be replaced by "Friend 1" and "" will be replaced by "Email 1". And the same will happen for the rest of the rows.

Important to note that the examples must come after the scenario outline directly. So the final definition will look like this.

Scenario Outline: Invite a friend
    Given I am logged in as "Ahmed"
    And I am on "home" screen
    When I tap "invite" button
    Then I write "<FriendEmail>" into the "Email" field
    And I write "<FriendName>" into the "Name" field
    And I tap "Invite Friend" button
    Then I should see "<FriendName> Invited" message

Examples:
    | FriendName | FriendEmail |
    |  Friend 1  |   Email 1   |
    |  Friend 2  |   Email 2   |
    |  Friend 3  |   Email 3   |
Clone this wiki locally