Mobile app automation testing with Calabash – Writing and Executing Test cases

Reading Time: 3 minutes


We will see how to write and execute test cases for Calabash. Before moving ahead, You must ensure that Calabash is setup properly on your system. If you need any help, refer to my earlier article on installation.

We will use a iOS demo project developed in Objective-C. We will see how to perform ‘Scroll’ through automation. It is hosted on GitHub and is open for anyone to try.

Step#0 Clone Repository

If you have already cloned above repository or, have created your test project. You can skip this step.

Once the repository is cloned try running the application in the simulator or on the actual device.

Step#1 Setup feature file

Open terminal at the path where you cloned/created your project and use the following command on your terminal to setup required files for writing test cases.

It will ask few questions.

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

When you hit yes it will create features folder. Under the features folder, you will see sample.feature and two more folders steps and support. These folders contain calabash automation supported files We shall discuss these folders in future articles.

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

Gemfile allows Ruby applications to manage the dependencies. It will add calabash-cucumber gem in this file.

Step#2 Writing test cases

Following is the way how I structured my test cases to perform ‘Scroll’ in the app. Calabash allows simple English language popularly known as Gherkin to write test cases for automating the app.

The first line initiates feature. Line 2 describes the feature, functionality or business value. The line 2 is not parsed at runtime. A feature file may only contain one feature and many scenarios. Line 4 is the starting point for the scenario. This describes a particular use case in the application. Line 5-10 describes steps to be executed for the mentioned scenario.

Gherkin, like Python and YML, is a line-oriented language which uses indentation to structure the file. Proper indentation is necessary in your test cases.

Step#3 Executing Test cases
  • Open terminal >> go to project directory >> enter ‘calabash-sandbox’ >> enter ‘cucumber’

Command “cucumber” will run all the test cases written in “*.feature” file.

After completion of running test cases, results will look like,

Screen Shot 2016-05-23 at 11.16.34 AM

Calabash-iOS Console

Calabash-iOS provides a console where you can search any elements and their properties in an app, It lists only elements which are currently visible on the screen.

You may see following messages on terminal

Screen Shot 2016-05-23 at 10.57.42 AM

this single command will work as accessibility inspector.

Screen Shot 2016-05-23 at 11.05.48 AM

Happy Testing!

Also published on Medium.

Quality Analyst and Software Tester by profession. I have great interest in learning automation tools. Deep down willing in iOS development and gradually moving towards it.