Calabash Android Testing Tool Tutorial

โšก Smart Summary

Calabash is an open-source acceptance testing framework that drives real user interface actions on Android and iOS applications, using plain-English Cucumber scenarios backed by Ruby step definitions and a device-side test server.

  • ๐Ÿ”ธ Definition: Calabash automates taps, text entry and assertions against native and hybrid mobile applications on real devices and emulators.
  • โ˜‘๏ธ Language stack: Scenarios are written in Gherkin feature files, and the matching methods live in Ruby files inside step_definitions.
  • โœ… BDD foundation: Behavior Driven Development lets business owners, developers and testers agree on behaviour before any script exists.
  • ๐Ÿงช Setup order: Java JDK, then Ruby, then Android Studio, then the calabash-android gem, verified with a version command.
  • ๐Ÿ› ๏ธ Execution flow: Resign the APK, build the test server, attach a device, query locators, then run the feature files.
  • ๐Ÿ“Š Current status: Calabash is archived and unmaintained, so new projects generally choose Appium, Espresso or XCUITest instead.

Calabash testing tool tutorial for Android showing Cucumber feature files driving a mobile application

What is Calabash?

Calabash is an open-source Acceptance Testing framework that allows you to write and execute tests for iOS and Android Apps.

It is an Automated User Interface Framework that allows tests to be written in Ruby using Cucumber.

Calabash works by enabling automatic UI interactions within a Mobile application such as pressing buttons, inputting text, validating responses, etc. It can be configured to run on different Android and iOS devices, which provides real-time feedback and validations.

โš ๏ธ Version note: Microsoft ended its contributions to Calabash after the final iOS 11 and Android 8 releases, and the calabash-android repository now describes itself as a project looking for a maintainer. The walkthrough below is preserved as written, and the modern replacements are covered in the last section.

Why Calabash Automation?

Before installing anything, it helps to weigh what the framework gives back against what it costs to maintain.

Advantages Disadvantages
It helps to increase throughput/ productivity. Proficiency is required to write the automation test scripts.
Improved quality or increased predictability of quality Debugging the test script is a major issue.
Improved robustness (consistency) of processes or products. Test maintenance is costly in case of playback methods.
Increased consistency of output and reduce labor costs and expenses Maintenance of test data files is difficult if the test script tests more screens

Calabash and BDD

  • Calabash is Behavior Driven Development (BDD). It is same as Test Driven Development (TDD), but instead of creating tests to describe the shape of APIs, application behavior is specified.
  • BDD is a process in which multiple stakeholders weigh in to create a common understanding of what has to be built.
  • BDD is helpful in building the right software and designing from the perspective of the business owner.

The diagram below shows how a Calabash suite is layered, from the business-readable feature file at the top down to the device interaction at the bottom.

Calabash BDD layer diagram showing feature files, step definitions and the device automation layer

How to install Calabash

Calabash on Windows needs four prerequisites installed in order. Complete each part fully before starting the next one, because the calabash-android gem checks for Ruby and the Android SDK during installation.

Part I) Install Java JDK โ€“ Refer to this guide โ€“ /install-java.html

Part II) Download and install Ruby.

Step 1) Download Ruby from the URL https://rubyinstaller.org/downloads

RubyInstaller download page listing the Ruby versions available for Windows

Step 2) Open the exe, follow the instructions on the screen. Once install is complete you will see the following screen. Click Finish.

Ruby setup wizard completion screen with the Finish button highlighted

Start Command Prompt with Ruby on Windows 10 & type below Command.

ruby -v

The console prints the installed interpreter version, as shown below.

Command Prompt with Ruby displaying the installed Ruby version number

Part III) Download and install Android

Step 1) Download Android Studio at https://developer.android.com/studio

Android Studio setup wizard running on Windows during installation

Step 2) Open the exe, follow the on-screen instructions and complete installation. Click the finish button once done

Android Studio installation finished screen with the finish button

Part IV) Install Calabash Android

Step 1) In the console type gem install calabash-android. The install will start and will take some time to complete

Console output while the calabash-android gem and its dependencies are installed

Step 2) Once installation is done Type calabash-android version

Console confirming the installed calabash-android gem version

Working with Calabash

With the gem installed, the next task is to locate the framework folder and understand the skeleton it ships with.

Open the “calabash-android-0.9.0” folder. It resides at path C:\Ruby23\lib\ruby\gems\2.3.0\gems\calabash-android-0.9.0. The folder names will change in synch with the ruby/ calabash version you install on your machine.

Open the feature skeleton folder. Look out for this basic framework.

Calabash feature skeleton folder containing support and step_definitions directories

  • The *.feature file contains scenarios that we are going to automate.
  • The method used by the feature file is written in *.rb file inside “step_definitions” folder.
  • Common methods, environment setup, app installation and hooks should be placed inside “support” folder.

Resign & Build the app

  • Calabash-android resign *.apk
  • Calabash-android build *.apk

Resigning replaces the developer signature with a debug key so the test server may instrument the application, and the build step produces that test server, as the console output below shows.

Console output of the calabash-android resign and build commands producing a test server

Attach the device to the system /Open the emulator

Check device attached. Type command

adb devices

Attached devices list should be displayed. If the device is missing, the USB debugging and pairing steps in the ADB connect guide resolve most cases.

adb devices command listing one attached Android device by serial number

How to Find the Element Locator

  • Open the console. Type the Command.
    calabash-android console "APK Path"
    start_test_server_in_background
  • Above command launch the app on the device. To find the element locator use following command.
    query "*"

This will display all the element locators on the current screen. Testers who prefer a visual inspector can cross-check the same hierarchy with uiautomatorviewer.

Calabash console printing the queried element tree for the current application screen

Calabash Project Structure and Predefined Steps

Rather than copying the gem folder by hand, the framework can generate a working project for you. Running the generator inside your project directory creates the standard Cucumber layout that every Calabash suite expects.

calabash-android gen

The generated tree separates the three concerns of a BDD suite:

  • features/ โ€” the Gherkin scenarios, one .feature file per user journey.
  • features/step_definitions/ โ€” the Ruby methods that match each Gherkin line, including the bundled calabash_steps.rb.
  • features/support/ โ€” environment configuration and the hooks that install, launch and shut down the application around every scenario.

The bundled calabash_steps.rb matters more than it first appears. It ships a large set of ready-made English steps, so a first scenario can press buttons, enter text and assert on visible strings before a single custom method is written. Custom steps are only needed once a journey outgrows those canned phrases.

Two project-level settings are worth knowing early. Screenshots land in the current working directory by default, and the SCREENSHOT_PATH environment variable redirects them elsewhere, which keeps build artefacts tidy on a shared machine. Interacting with system dialogs or another application requires the UIAutomator2 backend, started with start_test_server_in_background(with_uiautomator: true).

Creating New Scripts

Open the feature file and following lines

Login feature file opened in an editor showing the Gherkin scenario steps

Feature: Login feature
  Scenario: As a valid user I can log into my app
    When I press "Login"
    And I enter my username
    And I enter my password
    Then I see "Welcome to coolest app ever"

Open the Step Definition file & Define the method into *.rb file.

Ruby step definition file mapping a Gherkin line to a Calabash element query

Given /^I am on the login windows$/ do
   wait_for(:timeout =>100) { element_exists("* id:'loginInput;")}
   check_element_exists("* id:'loginInput;")
end

Execute the test project

To execute the test project, use command below

calabash-android run "APK Path" "feature file Path" --tags "tag name"

Cucumber prints each step as it executes, and a passing run ends with the scenario and step totals shown here.

Calabash run output showing each Gherkin step executing against the device

Calabash console summary reporting passed scenarios and step counts after execution

Common Calabash Errors and How to Fix Them

Most first-run failures come from the packaging and permission rules the test server depends on, not from the scenario itself. The table below maps the symptoms reported most often to their documented cause.

Symptom Likely cause and fix
The application crashes the instant a test starts The APK is missing android.permission.INTERNET, which the test server needs to accept commands. Declare the permission in AndroidManifest.xml and rebuild.
Buttons and text refuse to respond to taps No targetSdkVersion is declared. Add a uses-sdk entry naming the SDK level the application was built against.
The test server cannot connect to the application The APK was not resigned with the debug key. Run the resign command, then build again before running.
No devices are listed at run time USB debugging is off or the driver is missing. Confirm the serial number appears in the adb devices output first.
Steps fail with an undefined step error The Gherkin wording does not match any regular expression in step_definitions. Copy the suggested snippet Cucumber prints and implement it.

Two manifest entries fix the first two rows. Add them before resigning the APK.

<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:targetSdkVersion="SDK_VERSION" />

Timeout failures are usually environmental rather than functional. A slow emulator, a cold application start or a background sync can all push a screen past the wait_for window, so raise the timeout before rewriting a step that was actually correct.

Is Calabash Still Maintained? Alternatives for Modern Mobile Testing

Calabash is no longer actively developed. Microsoft stopped contributing after supporting the final iOS 11 and Android 8 releases, and the project is now an archived open-source code base without a maintainer. Existing suites still run on older devices, but new work should start on a supported framework.

Framework Platform Best suited to
Appium Android and iOS Cross-platform suites in Java, Python, Ruby or JavaScript, and the closest replacement for a Calabash team.
Espresso Android only Fast in-process tests written in Kotlin or Java by the application developers themselves.
XCUITest iOS only Native Xcode suites, the supported successor to the retired UIAutomation framework.
Maestro and Detox Android and iOS Newer open-source projects aimed at flake resistance and React Native applications.

The BDD habit itself transfers cleanly. Gherkin feature files stay exactly as they are, and only the step definition bodies change, because Cucumber sits above the driver rather than inside it. Teams migrating usually keep the feature files, rewrite the Ruby steps against Appium, and reuse the same mobile testing device matrix and automation testing pipeline they already run.

FAQs

Yes. A separate calabash-ios gem drove iOS applications through the same Ruby and Cucumber layer. It shares the deprecation status of the Android gem, so current iOS work is better served by XCUITest or Appium.

Machine learning models now repair broken locators automatically, flag flaky scenarios by comparing run histories, and cluster crash reports so the most damaging defects surface first. The judgement about what to assert still belongs to the tester.

Copilot drafts the repetitive parts well, such as a wait_for block wrapping an element query. It cannot know your application’s element identifiers, so treat every generated step as a draft to verify against a live query result.

Cucumber is the generic BDD runner that reads Gherkin and calls Ruby methods. Calabash is the mobile automation library those methods call. Cucumber decides what runs; Calabash performs the tap, the text entry and the assertion.

Screenshots are written to the current working directory by default, named sequentially per run. Setting the SCREENSHOT_PATH environment variable before the run redirects them to a chosen folder, which keeps continuous integration artefacts separate from source code.

No. Calabash instruments a compiled APK, which is why the resign step exists. Source access helps you add stable element identifiers, but the framework itself only needs a build it is allowed to resign and instrument.

Yes. Because execution is a single command-line call, any build server can invoke it after the APK is produced. A Jenkins job typically resigns the APK, starts an emulator, runs the tagged features and archives the reports.

Keep the Gherkin feature files unchanged and rewrite only the step definition bodies against the Appium client. Element queries become locator strategies, and the hooks that installed the application become desired capabilities in the driver setup.

Summarize this post with: