Calabash Android Tutorial (OSX)

I just wanted to try the calabash android project, which allows the definition of (semi) platform-independent test-cases.

Install Calabash

Ruby and Gem was already installed, so I just called (docs):

sudo gem install calabash-android 

Run the following command for a nice overview!

calabash-android help 

Prepare Example Project (Telegram Messanger)

I use a slighly modified version of the official android client of telegram as example for a simple test. This modifications are important to compile it. You can find the modified code on github.

The changes include following parts:

  • remove hockey (third-party service for app development)
  • add missing integer casts
  • fix keystore-extension (android studio forces the *.jks file-extension, but telegram uses *.keystore)
  • add multidex support to allow more than 65k methods (docs, stackoverflow)
  • hotfix: more memory for gc to avoid GC overhead java.lang.OutOfMemoryError: GC overhead limit exceeded (stackoverflow)

Build Libs

The telegram team removed pre-build native lib files (*.so-files) from the repository (see commit, stackoverflow). So you have to build them on your own.

  1. install NDK (see instructions)
  2. build it: navigate to the directory (e.g. Telegram/TMessagesProj/jni) and call ndk-build.

So they are only bugfixes and I had to remove debugging parts because I don't need them. Furthermore I changed the path to the keysore, because android studio forces the *.jks file-extension, but telegram uses in his build.gradle *.keystore.

git clone https://github.com/inkrement/Telegram.git

To get it running you also have to obtain API Keys from the telegram dev site.

Do not use Telegram as your Application Name and do not use the official icon (Ref)!

Update the Settings in your Telegram/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java.

Calabash requires a release build (see docs): Android Studio uses Build Variants to support multiple settings. I had to select release as default build type. This can be done in the Build Variants Window (docs).

Create Keystore

You have to create the keystore.. I used the telegram default location for releases (Telegram/TMessagesProj/config/release.keystore). In Android Studio you can create an keystore by selecting the Build-Menu entry Generate Signed APK.

The specific key settings are defined in the gradle.properties file. I'll use the default settings:

RELEASE_STORE_PASSWORD=password
RELEASE_KEY_ALIAS=alias
RELEASE_KEY_PASSWORD=password
I used pseudo-random values for the CA-fields, because at least one has to be non-empty. If you want to use it in production you should always use correct values, but here it's just for demonstration purposes.

Usage Example

I created a new folder for the test-files:

mkdir telegram-tests
cd telegram-tests

Then I called gen to generate the feature folder incl. some demo test

calabash-android gen

Then setup your keystore:

calabash-android setup

The output should look like this:

Warning: The following screenshot contains an error. The path of my keystore is wrong. It should be ~/Documents/dipl/Telegram/TMessagesProj/conf/release.jks. I solved it manually by editing the generated .calabash_settings file.

Now you can run your test cases. I tried the standard examples generated by calabash-android gen (They will fail, because they are just for demo purposes and not written for the telegram application).

calabash-android run ../Telegram/TMessagesProj/build/outputs/apk/TMessagesProj-release.apk

Tips

  • You can use the -v argument of calabash-android for debugging purposes.

Links