Module: Calabash::Android::TouchHelpers

Included in:
Operations
Defined in:
lib/calabash-android/touch_helpers.rb

Instance Method Summary collapse

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, options = {})
  center_x, center_y = find_coordinate(uiquery, options)

  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, options={})
  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 options[:offset]
    x += options[:offset][:x] || 0
    y += options[: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, options = {})
  center_x, center_y = find_coordinate(uiquery, options)
  length = options[: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, options={})
  options.merge!({action: lambda {|q| long_press(q, options)}})

  if options[:scroll] == true
    scroll_to(query_string, options)
  else
    when_element_exists(query_string, options)
  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, options={})
  options.merge!({action: lambda {|q| touch(q, options)}})

  if options[:scroll] == true
    scroll_to(query_string, options)
  else
    when_element_exists(query_string, options)
  end
end

#touch(uiquery, options = {}) ⇒ Object



28
29
30
31
32
# File 'lib/calabash-android/touch_helpers.rb', line 28

def touch(uiquery, options = {})
  center_x, center_y = find_coordinate(uiquery, options)

  perform_action("touch_coordinate", center_x, center_y)
end