Module: Calabash::Cucumber::IOS7Operations

Includes:
UIA
Included in:
Core
Defined in:
lib/calabash-cucumber/ios7_operations.rb

Instance Method Summary collapse

Methods included from UIA

#escape_uia_string, #send_uia_command, #uia_element_does_not_exist?, #uia_element_exists?, #uia_enter, #uia_handle_command, #uia_names, #uia_pan, #uia_pan_offset, #uia_pinch, #uia_pinch_offset, #uia_query, #uia_screenshot, #uia_scroll_to, #uia_send_app_to_background, #uia_set_location, #uia_swipe, #uia_swipe_offset, #uia_tap, #uia_tap_mark, #uia_tap_offset, #uia_type_string

Instance Method Details

#find_or_raise(ui_query) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/calabash-cucumber/ios7_operations.rb', line 86

def find_or_raise(ui_query)
  results = query(ui_query)
  if results.empty?
    screenshot_and_raise "Unable to find element matching query #{ui_query}"
  else
    results.first
  end
end

#ios7?Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/calabash-cucumber/ios7_operations.rb', line 10

def ios7?
  launcher = @calabash_launcher || Calabash::Cucumber::Launcher.launcher_if_used
  ENV['OS']=='ios7' || (launcher && launcher.device && launcher.device.ios7?)
end

#normalize_rect_for_orientation(rect) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/calabash-cucumber/ios7_operations.rb', line 29

def normalize_rect_for_orientation(rect)
  orientation = device_orientation().to_sym
  launcher = Calabash::Cucumber::Launcher.launcher
  screen_size = launcher.device.screen_size
  case orientation
    when :right
      cx = rect['center_x']
      rect['center_x'] = rect['center_y']
      rect['center_y'] = screen_size[:width] - cx
    when :left
      cx = rect['center_x']
      rect['center_x'] = screen_size[:height] - rect['center_y']
      rect['center_y'] = cx
    when :up
      cy = rect['center_y']
      cx = rect['center_x']
      rect['center_y'] = screen_size[:height] - cy
      rect['center_x'] = screen_size[:width]  - cx
    else
      # no-op by design.
  end
end

#pan_ios7(from, to, options = {}) ⇒ Object



79
80
81
82
83
84
# File 'lib/calabash-cucumber/ios7_operations.rb', line 79

def pan_ios7(from, to, options={})
  from_result = find_or_raise from
  to_result = find_or_raise to
  uia_pan_offset(point_from(from_result, options), point_from(to_result, options), options)
  [to_result]
end

#pinch_ios7(in_or_out, options) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/calabash-cucumber/ios7_operations.rb', line 65

def pinch_ios7(in_or_out, options)
  ui_query = options[:query]
  offset =  options[:offset]
  duration = options[:duration] || 0.5
  if ui_query.nil?
    uia_pinch_offset(in_or_out, offset, {:duration => options[:duration]})
  else
    el_to_pinch = find_or_raise(ui_query)
    offset = point_from(el_to_pinch, options)
    uia_pinch_offset(in_or_out, offset, duration)
    [el_to_pinch]
  end
end

#swipe_ios7(options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/calabash-cucumber/ios7_operations.rb', line 52

def swipe_ios7(options)
  ui_query = options[:query]
  offset =  options[:offset]
  if ui_query.nil?
    uia_swipe_offset(offset, options)
  else
    el_to_swipe = find_or_raise(ui_query)
    offset = point_from(el_to_swipe, options)
    uia_swipe_offset(offset, options)
    [el_to_swipe]
  end
end

#touch_ios7(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/calabash-cucumber/ios7_operations.rb', line 15

def touch_ios7(options)
  ui_query = options[:query]
  offset =  options[:offset]
  if ui_query.nil?
    uia_tap_offset(offset)
  else
    el_to_touch = find_or_raise(ui_query)
    rect = el_to_touch['rect']
    normalize_rect_for_orientation(rect)
    touch(el_to_touch, options)
    [el_to_touch]
  end
end