Mobile app automation testing with Calabash — Writing and Executing Test cases
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.
Calabash is an open source cross-platform framework developed by Xamarin that enables you to write and execute…www.promactinfo.com
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.
$ 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,
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
this single command will work as accessibility inspector.
Originally published at Promact — The Startup and Technology blog.