Google+ Followers

Monday, 3 February 2014

calabash android: useful commands

1) back arrow & Menu key
performAction('go_back')



performAction('press_menu')

2) Enter key on virtual key pad 
  performAction('send_key_enter')

3) Swipe right and left / Scroll up down

  performAction('swipe', 'left')
  performAction('swipe', 'right')


  performAction('scroll_down')
  performAction('scroll_up')


4) wait until time_out (seconds) for particular text to be shown ,
if text is shown return true else false

  def wait_for_page_to_load(text, time_out)
    begin
      wait_poll({:until_exists => "* marked:'#{text}'", :timeout => time_out}) do
        puts "wait_for_page_to_load: checking text #{text}"
      end
    rescue
      return false
    end
    return true
  end

5) Scroll up and down

  def scroll_view(dir)
    if (dir=="up")
      performAction('drag', 50, 50, 70, 90, 10)
    elsif (dir=="down")
      performAction('drag', 50, 50, 90, 70, 10)
    end
  end

6) Read test data from excel
require 'rubyXL'

def read_test_data()
    file_path=$g_booking_data
    
workbook = RubyXL::Parser.parse(file_path)
    hash_arr=workbook[1].get_table(["Surname", "Today"])
    return hash_arr[:table]
  end




7 comments:

  1. How to enter other keys from virtual keypad to the app text field ??

    ReplyDelete
  2. use this method


    def enter_text_android(text)
    sleep 2
    command = "#{default_device.adb_command} shell input text '#{text.to_s}'"
    raise "Could not send text" unless system(command)
    end

    ReplyDelete
  3. How to check button element and press if its true then proceed to the next steps if false.

    ReplyDelete
  4. use element_exists to check if the element is present
    example:

    if element_exists(query)
    // do some steps
    end

    ReplyDelete
  5. performAction('drag', 50, 50, 70, 90, 10) .. could you please explain the parameters used in drag function . The first 4 parameters are x and y co-ordinates. How did you get that value? and what's 10 ?

    ReplyDelete
    Replies
    1. performAction('drag',fromX,toX,fromY,toY,steps)

      Delete