Module: Calabash::Android::TouchHelpers
- Included in:
- Operations
- Defined in:
- lib/calabash-android/touch_helpers.rb
Instance Method Summary collapse
- #double_tap(uiquery, options = {}) ⇒ Object
- #find_coordinate(uiquery, options = {}) ⇒ Object
-
#long_press(uiquery, options = {}) ⇒ Object
Performs a “long press” operation on a selected view Params:
uiquery
: a uiquery identifying one viewoptions[:length]
: the length of the long press in milliseconds (optional). - #long_press_when_element_exists(query_string, options = {}) ⇒ Object
- #tap(mark, *args) ⇒ Object
- #tap_when_element_exists(query_string, options = {}) ⇒ Object
- #touch(uiquery, options = {}) ⇒ Object
Instance Method Details
#double_tap(uiquery, options = {}) ⇒ Object
8 9 10 11 12 |
# File 'lib/calabash-android/touch_helpers.rb', line 8 def double_tap(uiquery, = {}) center_x, center_y = find_coordinate(uiquery, ) perform_action("double_tap_coordinate", center_x, center_y) end |
#find_coordinate(uiquery, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/calabash-android/touch_helpers.rb', line 34 def find_coordinate(uiquery, ={}) raise "Cannot find nil" unless uiquery element = execute_uiquery(uiquery) raise "No elements found. Query: #{uiquery}" if element.nil? x = element["rect"]["center_x"] y = element["rect"]["center_y"] if [:offset] x += [:offset][:x] || 0 y += [:offset][:y] || 0 end [x, y] end |
#long_press(uiquery, options = {}) ⇒ Object
Performs a “long press” operation on a selected view Params: uiquery
: a uiquery identifying one view options[:length]
: the length of the long press in milliseconds (optional)
Examples:
- long_press("* id:'my_id'")
- long_press("* id:'my_id'", {:length=>5000})
22 23 24 25 26 |
# File 'lib/calabash-android/touch_helpers.rb', line 22 def long_press(uiquery, = {}) center_x, center_y = find_coordinate(uiquery, ) length = [:length] perform_action("long_press_coordinate", center_x, center_y, *(length unless length.nil?)) end |
#long_press_when_element_exists(query_string, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/calabash-android/touch_helpers.rb', line 62 def long_press_when_element_exists(query_string, ={}) .merge!({action: lambda {|q| long_press(q, )}}) if [:scroll] == true scroll_to(query_string, ) else when_element_exists(query_string, ) end end |
#tap(mark, *args) ⇒ Object
4 5 6 |
# File 'lib/calabash-android/touch_helpers.rb', line 4 def tap(mark, *args) touch("* marked:'#{mark}'", *args) end |
#tap_when_element_exists(query_string, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/calabash-android/touch_helpers.rb', line 52 def tap_when_element_exists(query_string, ={}) .merge!({action: lambda {|q| touch(q, )}}) if [:scroll] == true scroll_to(query_string, ) else when_element_exists(query_string, ) end end |
#touch(uiquery, options = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/calabash-android/touch_helpers.rb', line 28 def touch(uiquery, = {}) center_x, center_y = find_coordinate(uiquery, ) perform_action("touch_coordinate", center_x, center_y) end |