Road to create and execute Calabash Android test for beginner

In my previous post I have written how to setup calabash android and how to find element locator details using calabash console. In this post I will show you how to create calabash android test. Also I will show you, how to generate report.

Steps to write scenario:
After running command >> calabash-android gen   calabash-android automatically generates cucumber skeleton folder-structure. Now you write cucumber test scenario for your application test scenario into created “my_first.feature” file as written below:

Feature: Login feature to andriod app
 
  @LoginAPP
  Scenario: As a valid user log in to app
    When I press "Login"
    Then I see "Login"
    Then I wait user imput field
    Then I enter valid user name
    Then I enter valid password
    Then I click on ligin Button
    Then I wait Logout Button
    Then I click Logout Button

For above steps you need to write function in ruby language and put .rb file under “step_definitions” folder, as I created login.rb file for below functions.

require 'calabash-android/calabash_steps'

When /^I wait user imput field$/ do
   wait_for(:timeout => 20){ element_exists("* id:'login_usr'")}     
end

When /^I enter valid user name$/ do
    query("* id:'login_usr'",{:setText => "Admin"})   
end

When /^I enter valid password$/ do   
    query("* id:'login_pwd'",{:setText => "Admin"})
end

Then /^I click on ligin Button$/ do
    touch(query("* id:'login_btn'"))
end

Then /^I wait Logout Button$/ do
   wait_for(:timeout => 20) { element_exists("button marked:'LOGOUT'") }      
end

Then /^I click Logout Button$/ do    
    touch(query("* id:'logout_btn'"))
end

Execution:

Open command prompt and go to calabash project root directory and run below command to execute calabash test
calabash-android run ${APKFile} -f html -o test-result.html

-f html f flag is use to create report in xml format.
-o generates report in mentioned html file.
Report:

After execution report is generated in below html format. Failed scenario  marked red with test step, passed step and scenario marked green as mentioned in following screen shots.




4 comments:

  1. nice post for reporting

    ReplyDelete
  2. Thanks for this post, Really it is very helpful to generate report in html format.

    ReplyDelete
  3. Thank you so much! You really don't understand how much this has helped me - been struggling for about 3 hours straight! ahh cheers :)

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution