Saturday, May 18, 2013

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

23 comments:

  1. I am facing problem in signing the app, Please help me.. below is the error.


    C:\My_Android_app>calabash-android resign silverdroid.apk
    jarsigner command: "/bin/jarsigner.exe" -sigalg MD5withRSA -digestalg SHA1 -sign
    edjar C:/My_Android_app/silverdroid.apk -storepass android -keystore "C:/Users/S
    hailendra/.android/debug.keystore" C:/Users/SHAILE~1/AppData/Local/Temp/d2013061
    5-8964-1jnvmg8/unsigned.apk androiddebugkey
    C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.4.6/lib/calabash-android/
    helpers.rb:79:in `sign_apk': Could not sign app (C:/Users/SHAILE~1/AppData/Local
    /Temp/d20130615-8964-1jnvmg8/unsigned.apk (RuntimeError)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.4.6/lib/cala
    bash-android/helpers.rb:62:in `block in resign_apk'
    from C:/Ruby193/lib/ruby/1.9.1/tmpdir.rb:83:in `mktmpdir'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.4.6/lib/cala
    bash-android/helpers.rb:55:in `resign_apk'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/calabash-android-0.4.6/bin/cala
    bash-android:112:in `'
    from C:/Ruby193/bin/calabash-android:23:in `load'
    from C:/Ruby193/bin/calabash-android:23:in `'

    C:\My_Android_app>

    ReplyDelete
    Replies
    1. Refer Section - http://mobileappautomation.blogspot.in/2013/05/calabash-android-for-automating-tests.html

      Delete
  2. I already tried that, here I am getting error on below step that jarsigner is not recognized command..

    Type > jarsigner -keystore debug.keystore -storepass android -keypass android AndroidDemoProject.apk androiddebugkey > click enter.

    ReplyDelete
  3. hi Shailendra, did you find the solution to the jarsigner not recognized error?
    Please share. I'm getting this error too. Thanks, TM.

    ReplyDelete
  4. Did you guys able to resolve jarsigner issue ? do you have the correct java version installed and path set for java-home !!

    ReplyDelete
    Replies
    1. The jarsigner issue does not seem to be resolved. I've tried multiple times with various JDK versions (1.7.0_21, 1.6.0_45). I'm running Linux Mint 15:

      calabash-android resign Logos-111.apk --verbose
      2013-07-08 19:44:54 - Resign apk
      2013-07-08 19:44:54 - jarsigner -sigalg MD5withRSA -digestalg SHA1 -signedjar /home/user/Downloads/android-sdk-linux/tools/scripts/dev/Logos-111.apk -storepass password -keystore "/home/user/.keystore" /tmp/d20130708-32057-1f6pg3m/unsigned.apk mykey
      jarsigner: unable to open jar file: /tmp/d20130708-32057-1f6pg3m/unsigned.apk
      jarsigner command: jarsigner -sigalg MD5withRSA -digestalg SHA1 -signedjar /home/user/Downloads/android-sdk-linux/tools/scripts/dev/Logos-111.apk -storepass password -keystore "/home/user/.keystore" /tmp/d20130708-32057-1f6pg3m/unsigned.apk mykey
      /var/lib/gems/1.9.1/gems/calabash-android-0.4.6/lib/calabash-android/helpers.rb:79:in `sign_apk': Could not sign app (/tmp/d20130708-32057-1f6pg3m/unsigned.apk (RuntimeError)
      from /var/lib/gems/1.9.1/gems/calabash-android-0.4.6/lib/calabash-android/helpers.rb:62:in `block in resign_apk'
      from /usr/lib/ruby/1.9.1/tmpdir.rb:83:in `mktmpdir'
      from /var/lib/gems/1.9.1/gems/calabash-android-0.4.6/lib/calabash-android/helpers.rb:55:in `resign_apk'
      from /var/lib/gems/1.9.1/gems/calabash-android-0.4.6/bin/calabash-android:112:in `'
      from /usr/local/bin/calabash-android:23:in `load'
      from /usr/local/bin/calabash-android:23:in `'

      Delete
    2. I had the same issue. I was able to fix it by adding %JAVA_HOME%/bin in the path environment variables. jarsigner.exe file in the bin directory for java.

      Delete
  5. Hi Amit,

    Here i am using my own apk for calabash android automation testing. After incorporating the above steps, following exception is occurred:-

    c:\Ruby193\lib\ruby>calabash-android run "C:\Ruby193\lib\ruby\BuyCokeAndroid.apk
    "
    Feature: Buy Coke

    Scenario: Wrong account number # features\my_first.featur
    e:3
    565 KB/s (529028 bytes in 0.914s)
    80 KB/s (107586 bytes in 1.303s)
    Given my app is running # calabash-android-0.4.4/l
    ib/calabash-android/steps/app_steps.rb:6
    And I enter "85461298" as "account number" # calabash-android-0.4.4/l
    ib/calabash-android/steps/enter_text_steps.rb:1
    Step unsuccessful: No view found with content description: 'account number
    ' (RuntimeError)
    C:/Ruby193/lib/ruby/1.9.1/timeout.rb:69:in `timeout'
    features\my_first.feature:5:in `And I enter "85461298" as "account number"
    '
    Then I press "Save" # calabash-android-0.4.4/l
    ib/calabash-android/steps/press_button_steps.rb:17
    And I wait for "missing account" to appear # calabash-android-0.4.4/l
    ib/calabash-android/steps/progress_steps.rb:27
    Then I press "account" to re-enter account number # features\my_first.featur
    e:8

    Failing Scenarios:
    cucumber features\my_first.feature:3 # Scenario: Wrong account number

    1 scenario (1 failed)
    5 steps (1 failed, 2 skipped, 1 undefined, 1 passed)
    1m16.567s

    You can implement step definitions for undefined steps with these snippets:

    Then /^I press "(.*?)" to re\-enter account number$/ do |arg1|
    pending # express the regexp above with the code you wish you had
    end

    My cucumber steps:-

    Feature: Buy Coke

    Scenario: Wrong account number
    Given my app is running
    And I enter "85461298" as "account number"
    Then I press "Save"
    And I wait for "missing account" to appear
    Then I press "account" to re-enter account number

    Regards,
    Vijaykumar

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Same problem is resolved at my end.... after update the gems and set Java home path(root path). My window's Java version is (build 1.7.0-b147)

    ReplyDelete
  8. Hi,
    The article is very good!! As per your guidance, I have done all the configuration and it is working fine for my Demo application developed using Native android. And it is returning two buttons. See below:
    irb(main):003:0> query("button")
    [
    [0] {
    "id" => "help_btn",
    "enabled" => true,
    "contentDescription" => "help",
    "class" => "android.widget.Button",
    "text" => "?",
    "rect" => {
    "center_y" => 173.0,
    "center_x" => 420.0,
    "height" => 54,
    "y" => 146,
    "width" => 30,
    "x" => 405
    },
    "description" => "android.widget.Button{40cfd200 VFED..C. ......I. 360,12-390,66 #7f07000c app:id/help_btn}"
    },
    [1] {
    "id" => "login_btn",
    "enabled" => true,
    "contentDescription" => nil,
    "class" => "android.widget.Button",
    "text" => "LOGIN",
    "rect" => {
    "center_y" => 429.0,
    "center_x" => 345.0,
    "height" => 72,
    "y" => 393,
    "width" => 180,
    "x" => 255
    },
    "description" => "android.widget.Button{40d04358 VFED..C. ......I. 255,259-435,331 #7f070010 app:id/login_btn}"
    }
    ]
    irb(main):004:0>

    ---------------
    But it is not recognizing the controls of my another application. This is a Hybrid Application and developed into PhoneGap. When I ran the query for button, it is returning nothing. See below:

    irb(main):002:0> query("button")
    []
    irb(main):003:0>

    Please guide me to test my application developed into Phonegap. Is there any additional setting need to be done for PhoneGap??

    Any help would be appreciated.

    ReplyDelete
  9. I Have followed the steps mentioned above but i am getting error
    No test server found for this combination of app and calabash version. Recreatin
    g test server.
    No keystores found.
    Please create one or run calabash-android setup to configure calabash-android to
    use an existing keystore.
    please any one help me how to solve this error

    ReplyDelete
  10. I have executed demo project. I wanted to execute different apk file. I tried to execute, but old apk is getting executed. How to execute the latest apk. In which file i need to do changes. Can you please give me the solution for this.

    ReplyDelete
  11. Outstanding blog.You can now get best services for software testing and Mobile App testing at Salvus App Solutions which offers you services for software testing, SEO, ASO, etc. All OS apps are tested here. 

    ReplyDelete
  12. During the set up you’ll have to allow an app called “Azure Stack” to access your Azure AD instance in the cloud and once its up. Business Centre Shanghai

    ReplyDelete
  13. Great informational resource as always!I really love the way of explaining this post.You are just ouststanding...Keep posting more.
    top android app development companies | best seo services

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Supplements For Fitness exercise option. If you plan on going to the gym, you should make sure to give it time to visit. Needless to say, you will not see any results if you are going to the gym only for a few weeks and then stop walking suddenly. This is the reason why many people often give up. When it comes to the diet process,

    ReplyDelete
  16. Pilpedia is supplying 100 percent original and accurate information at each moment of time around our site and merchandise, and the intent is to improve the usage of good and pure health supplement. For More Info please visit Pilpedia online store.

    ReplyDelete
  17. Lipo Cla Avis
    Le problème pour l’obtention d’une silhouette parfaite est actuel, comme en témoigne l’intérêt porté à cette question dans différentes sources.
    https://care2fit.com/lipo-cla-avis/

    ReplyDelete
  18. thanks a lot for all the measures and efforts you took us here to make us more distinctive with our knowledge and thinking criteria.
    Morgan @ Gowell Health Tips

    ReplyDelete
  19. Thank you for sharing excellent informations. Your web-site is very cool.
    Home Improvement Write for us

    ReplyDelete
  20. That visitors and readers can easily Understand the concept.I Efforts must appreciate you posting these on informationBeauty + write for us"

    ReplyDelete