Showing posts with label mobile app testing using calabash android. Show all posts
Showing posts with label mobile app testing using calabash android. Show all posts

Monday, May 27, 2013

Calabash-android for automating tests

Please refer the section - Setup for calabash-android

1) Create the sample .apk 
For learning purpose download calabash-android-demoapp 
    - Download the zip file "calabash-android-demoapp-master.zip"
    - Create a folder "AndroidDemoProject"
    - Extract the zip file to "AndroidDemoProject" folder
    - Launch Eclipse
    - Navigate File > Import > and Select - Existing Android code into workspace
    - Click Next
    - Import Project - Browse and Select \\AndroidDemoProject\calabash-android-demoapp-master
    - Click Finish
    - Select project AndroidDemoProject and right-click
    - From the menu pop-up select Android Tools > Export Unsigned Application Package

2) Save AndroidDemoProject.apk file to the folder

3) Generate a Cucumber skeleton :
  In CMD prompt, go to the  "AndroidDemoProject" folder and Run the command C:\AndroidDemoProject\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
 


4) Open the file my_first.feature and enter the following text:

 Feature: Demo feature
 Scenario: I can start my app
    And I wait for "Hello World, AndroidDemoProject" to appear
    And take picture

5) Finally - Execute Test code:
  From CMD prompt C:\AndroidDemoProject\calabash-android run AndroidDemoProject.apk

*** In Case you get the following Error****
C:\AndroidDemoProject>calabash-android run AndroidDemoProject.apk
No test server found for this combination of app and calabash version. Recreating test server.
C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.4.4/lib/calabash-android/
helpers.rb:145:in `block (2 levels) in fingerprint_from_apk': No RSA file found in META-INF. Cannot proceed. (RuntimeError)

This is because the .apk should be signed

Follow the Steps below to overcome the above Error
  • Copy AndroidDemoProject.apk file to this folder - C:\Users\<UserName>\.android>
  • In CMD prompt, go to this location: C:\Users\<username>\.android
  • Type > jarsigner -keystore debug.keystore -storepass android -keypass android AndroidDemoProject.apk androiddebugkey > click enter. 
  • We are done with the signing part
  •  Copy AndroidDemoProject.apk and replace file in folder AndroidDemoProject 
Repeat Step 5 above - The Test should be Successful

*** In Case Even after signing the .apk - you are getting the following bellow error****

android.util.AndroidException: INSTRUMENTATION_FAILED: sh.calaba.demoproject.tes
t/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
        at com.android.commands.am.Am.runInstrument(Am.java:676)
        at com.android.commands.am.Am.run(Am.java:119)
        at com.android.commands.am.Am.main(Am.java:82)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
        at dalvik.system.NativeStart.main(Native Method)
  App did not start (RuntimeError)


You need to resign the .apk

Follow the Steps below to overcome the above Error
  • From CMD prompt C:\AndroidDemoProject\calabash-android resign AndroidDemoProject.apk
Repeat Step 5 above - The Test should be Successful

*** In Case you get the following Error****
No connected devices (RuntimeError)
Connect your "mobile device" or "simulator" where you want to test your code:
Repeat Step 5 above - The Test should be Successful