fbpx

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.

https://www.promactinfo.com/blog/mobile-app-automation-testing-with-calabash-installation-ios/

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.

$ git clone https://github.com/Promact/ios-sample-calabash.git

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.

$ calabash-ios gen

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.

Feature: Scroll the Table
  Functionality of this test case is to test scrolling

  Scenario: Scroll Scenario
    Given I wait to see a navigation bar titled "To do List"
    When I scroll down
    Then I wait for 2 seconds
    Then I scroll down
    Then I wait for 2 seconds
    Then I scroll up

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.

$ calabash-iso console

You may see following messages on terminal

Screen Shot 2016-05-23 at 10.57.42 AM
> query("*")

this single command will work as accessibility inspector.

Screen Shot 2016-05-23 at 11.05.48 AM

Happy Testing!

A Geek by nature, I love to work on challenging development projects. I have been in Programming for last 13 years and still too young to learn anything new. I have exceptional command using AngularJS and Python/.Net/NodeJS.

Leave a Reply

Your email address will not be published. Required fields are marked *