Nested Examples: in a Cucumber Feature File

2.1k views Asked by At

Is something like the following possible? I am testing using calabash-android.

I have 3 types of users
I want to log each of the 3 in and make sure the screen has each of the 9 elements.

Can I nest the 3 user types and then have each user type look for each of the 9 elements?

Feature: Overview screen on Mobile App
  In order to access all the features of the Mobile App
  As a user of the Mobile App
  I want to be able to access the features through the Overview Screen

  @high
  Scenario Outline: Overview Screen Appearance
    Given I login to an <type> account

    Examples:
      | type          |
      | secure        |
      | user          |
      | admin         |

    Then I should see the <element>

    Examples:
      | element                     |
      | Overview Header             |
      | Status Icon                 |
      | Status Text                 |
      | Status Time                 |
      | Current Temp Icon           |
      | Navigation Overview Text    |
      | Navigation Overview Icon    |
      | Navigation Activity Text    |
      | Navigation Activity Icon    |

Thanks

2

There are 2 answers

1
Jörn Horstmann On BEST ANSWER

That sounds more like a task for using a datatable. The code implementing the step would then check that each element of the datatable parameter is present on the page.

Scenario Outline: Overview Screen Appearance
  Given I login to an <type> account
  Then I should see the following elements:
    | element                     |
    | Overview Header             |
    | Status Icon                 |
    | Status Text                 |
    | Status Time                 |
    | Current Temp Icon           |
    | Navigation Overview Text    |
    | Navigation Overview Icon    |
    | Navigation Activity Text    |
    | Navigation Activity Icon    |
  Examples:
    | type          |
    | secure        |
    | user          |
    | admin         |
0
Vishal Aggarwal On

You may also consider using FactoryGirl.

If you have complex data model, you can simply abstract it out in the form of factories instead of making complex static feature files.