Visual Studio App Center Test is the next generation of Xamarin Test Cloud! Read the blog post.

Creating A Calabash Test for an iOS App

PDF for offline use
Related Links:

Let us know how you feel about this

Translation Quality


0/250

last updated: 2016-09

At this point we should have the Calabash gems installed and an iOS app that we can use for testing. We can now get started with writing the test.

Create the features Folder

The features folder is a special folder where calabash-ios expects the test code to reside. Calabash can create this folder and provide some boilerplate code to get us started. Start up a Terminal session, and change the working directory to directory that contains SimpleCreditCardValidator.xcodeproj, i.e.:

In the project folder, run calabash-ios gen as shown below:

[tom@calabash-sandbox]$ calabash-ios gen

----------Question----------
I'm about to create a features directory here:

/Users/tom/temp/SimpleCreditCardValidator/features

This directory will contain all of your calabash tests.
Shall I proceed? (Y/n)
---------------------------
y

Created: /Users/tom/temp/SimpleCreditCardValidator/features


----------Question----------
I want to create a Gemfile for you.
Shall I proceed? (Y/n)
y

Created: /Users/tom/temp/SimpleCreditCardValidator/Gemfile

---------------------------
My work is done here.

This has created a features folder with the following structure:

Lets move on to create the first test.

Creating the First Test

To create the first test, edit the text file features/sample.feature and replace the existing contents with the following:

Feature: Credit card validation.
  Credit card numbers must be exactly 16 characters.

  Scenario: Credit card number is too long
    Given I wait to see a navigation bar titled "Simple Credit Card Validator"
    When I enter "99999999999999999" into input field number 1
    When I touch the "Validate Credit Card" button
    Then I should see "Credit card number is too long."

Here is a quick description of this snippet:

  • A Feature must have name, and may optionally provide a description. A Feature is broken down into Scenarios.
  • A Scenario is a formal example of how the Feature (or a rule in the Feature) works.
  • Scenarios, in turn, are broken down into Steps. This particular feature uses predefined steps. It is also possible to create your own custom Steps, but that is beyond the scope of this quick start.

Save the changes to features/sample.feature.

Running the Test in the iOS Simulator

Now that we have created the test, let's run it locally against the iOS simulator before submitting it to Xamarin Test Cloud. It is possible to run the test on a device, however for the purposes of this quick start

At the command prompt, run cucumber:

$ bundle exec cucumber
Feature: Credit card validation.
  Credit card numbers must be exactly 16 characters.

INFO: Detected app at path:
INFO: /Users/tom/temp/SimpleCreditCardValidator/DerivedData/SimpleCreditCardValidator/Build/Products/Debug-iphonesimulator/SimpleCreditCardValidator.app
INFO: Modification time of app: Tue 27 Sep 2016 14:46:24 MDT
INFO: If this is incorrect, set the APP variable and/or rebuild your app
INFO: It is your responsibility to ensure you are testing the right app.
  Scenario: Credit card number is too long                                     # features/sample.feature:4
    Given I wait to see a navigation bar titled "Simple Credit Card Validator" # calabash-cucumber-0.20.0/features/step_definitions/calabash_steps.rb:169
    When I enter "99999999999999999" into input field number 1                 # calabash-cucumber-0.20.0/features/step_definitions/calabash_steps.rb:125
    When I touch the "Validate Credit Card" button                             # calabash-cucumber-0.20.0/features/step_definitions/calabash_steps.rb:30
    Then I should see "Credit card number is too long."                        # calabash-cucumber-0.20.0/features/step_definitions/calabash_steps.rb:313

1 scenario (1 passed)
4 steps (4 passed)
0m48.717s

With the test passing locally, it's time to run it in Xamarin Test Cloud. To do this, we must first create a team test run in Xamarin Test Cloud.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.