Saturday, May 18, 2013

Usefull Commands

1. To Start emulator from command prompt :
emulator @yourAvdName

2. To Run a specified feature file :
calabash-android run <your_apk_file>.apk features/<feature_1>.feature  

3. To Generate HTML Report
calabash-android run <your_apk_file>.apk --format html --out test_report.html

4. command to know the installed calabash\cucumber gem version
gem list calabash-android
gem list calabash-cucumber

JumpStart Android Testing using Calabash

This Post will help you to write your First Functional Test using calabash and cucumber.

Before we Jump Start to this - Let me ASK you two questions :

1. Do you have the .apk file of the mobile app you are planning to test ?
If  NO - please get it first and put it in some folder say C:\My_Android_App\<your_apk_file>.apk

2. Do you have install the pre-requisties tools ?
If NO - Please refer the section - Setup for calabash-android 

STEP 1:
Using command prompt Navigate to the folder where you have your .apk file

STEP 2:
Generate a Cucumber skeleton :
Run the command C:\My_Android_App\calabash-android gen
It will create a Cucumber skeleton in the current folder like this:

features
|_support
| |_app_installation_hooks.rb
| |_app_life_cycle_hooks.rb
| |_env.rb
|_step_definitions
| |_calabash_steps.rb
|_my_first.feature
 


In this skeleton you find all the predefined steps that comes with calabash. Try to take a look my_first.feature and change it to fit your app.

STEP 3:
Resign your apk with the default "debug.keystore" available at C:\Users\<your_user_name>\.android
Run the command C:\My_Android_App\calabash-android resign <your_apk_file>.apk

STEP 4:
Connect your "mobile device" or "simulator" where you want to test your code:
Run the command C:\My_Android_App\adb devices
*** The device or simulator should show in the List of devices attached***

STEP 5:
Finally - Execute Test code:
Run the command C:\My_Android_App\calabash-android run <your_apk_file>.apk

Setup for Calabash-android

The First and foremost things is to have all the prerequisites tools installed in your system. The below are the step by step explanation of how to quickly setup your development environment for functional testing of mobile apps (android) using Cucumber and Calabash-android.

Pre-Requisites:

1. You need to have Ruby installed. Verify your installation by running ruby -v in a terminal - it should print "ruby 1.8.7" (or higher).



***If you are on Windows you can get Ruby from RubyInstaller.org ***
http://rubyinstaller.org/downloads/

2. You should have the Android SDK installed and the environment variable ANDROID_HOME should be pointing to it.


Note :  Make Sure Following Environment variables should be set properly
====================================================
Set the Android path to the directory where you have the android sdk installed :
ANDROID_HOME=C:\Android-SDK\adt-bundle-windows-x86_64-20130219\sdk

STEP 1 : Install Cucumber
Navigate to Command Prompt and type "gem install cucumber"



*** In case you face any problem refer Tips Section***

STEP 2 : Install Calabash-android
Navigate to Command Prompt and type "gem install calabash-android"




***You might have to run sudo gem install calabash-android if you do not have the right permissions.***

*** In case you face any problem refer Tips Section***


That's all ....
YOU are now set to write your First Functional Test - Refer "JumpStart Android Testing using Calabash"