Module: Appium::Ios::Xcuitest::Gesture

Defined in:
lib/appium_lib/ios/xcuitest/command/gestures.rb

Instance Method Summary collapse

Instance Method Details

#alert(action:, button_label: nil) ⇒ Object

Returns {} or Selenium::WebDriver::Error::NoSuchAlertError if no action sheet or alert or button labels if action is equal to getButtons.

“‘ruby alert action: “accept” alert action: “dismiss” “`.

Parameters:

  • action (String)

    The following actions are supported: accept, dismiss and getButtons. Mandatory parameter

  • button_label (String) (defaults to: nil)

    The label text of an existing alert button to click on. This is an optional parameter and is only valid in combination with accept and dismiss actions.

Returns:

  • {} or Selenium::WebDriver::Error::NoSuchAlertError if no action sheet or alert or button labels if action is equal to getButtons.

    “‘ruby alert action: “accept” alert action: “dismiss” “`



182
183
184
185
186
187
188
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 182

def alert(action:, button_label: nil)
  return 'Set "accept", "dismiss" or "getButtons" for :action' unless %w(accept dismiss getButtons).include?(action)

  args = { action: action }
  args[:button_label] if button_label
  @driver.execute_script 'mobile: alert', args
end

#double_tap(x: nil, y: nil, element: nil) ⇒ Object

Parameters:

  • x (float) (defaults to: nil)

    X Screen x tap coordinate of type float. Mandatory parameter only if element is not set

  • y (float) (defaults to: nil)

    Y Screen y tap coordinate of type float. Mandatory parameter only if element is not set

  • opts (Hash)

    a customizable set of options



82
83
84
85
86
87
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 82

def double_tap(x: nil, y: nil, element: nil)
  return 'Set x, y or element' if (x.nil? || y.nil?) && element.nil?

  args = element.nil? ? { x: x, y: y } : { element: element.id }
  @driver.execute_script 'mobile: doubleTap', args
end

#drag_from_to_for_duration(from_x:, from_y:, to_x:, to_y:, duration: 1.0, element: nil) ⇒ Object

rubocop:disable Metrics/ParameterLists

Parameters:

  • duration (float) (defaults to: 1.0)

    Float number of seconds in range [0.5, 60]. How long the tap gesture at starting drag point should be before to start dragging. Mandatory parameter

  • from_x (float)

    The x coordinate of starting drag point (type float). Mandatory parameter

  • from_y (float)

    The y coordinate of starting drag point (type float). Mandatory parameter

  • to_x (float)

    The x coordinate of ending drag point (type float). Mandatory parameter

  • to_y (float)

    The y coordinate of ending drag point (type float). Mandatory parameter

  • opts (Hash)

    a customizable set of options



147
148
149
150
151
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 147

def drag_from_to_for_duration(from_x:, from_y:, to_x:, to_y:, duration: 1.0, element: nil)
  args = { fromX: from_x, fromY: from_y, toX: to_x, toY: to_y, duration: duration }
  args[:element] = element.id if element
  @driver.execute_script 'mobile: dragFromToForDuration', args
end

#one_finger_tap(x:, y:, element: nil) ⇒ Object

Parameters:

  • x (float)

    X tap coordinate of type float. Mandatory parameter

  • y (float)

    Y tap coordinate of type float. Mandatory parameter

  • opts (Hash)

    a customizable set of options



127
128
129
130
131
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 127

def one_finger_tap(x:, y:, element: nil)
  args = { x: x, y: y }
  args[:element] = element.id if element
  @driver.execute_script 'mobile: tap', args
end

#pinch(scale:, velocity: 1.0, element: nil) ⇒ Object

Parameters:

  • scale (scale)

    X tap coordinate of type float. Mandatory parameter

  • velocity (float) (defaults to: 1.0)

    Y tap coordinate of type float. Mandatory parameter

  • opts (Hash)

    a customizable set of options



67
68
69
70
71
72
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 67

def pinch(scale:, velocity: 1.0, element: nil)
  args = { scale: scale, velocity: velocity }
  args[:element] = element.id if element

  @driver.execute_script 'mobile: pinch', args
end

#scroll(direction:, distance: nil, name: nil, element: nil, to_visible: nil, predicate_string: nil) ⇒ Object

rubocop:disable Metrics/ParameterLists

Parameters:

  • direction (string)

    Either ‘up’, ‘down’, ‘left’ or ‘right’.

  • opts (Hash)

    a customizable set of options



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 46

def scroll(direction:, distance: nil, name: nil, element: nil, to_visible: nil, predicate_string: nil)
  return 'Set "up", "down", "left" or "right" for :direction' unless %w(up down left right).include?(direction)

  args = { direction: direction }
  args[:element] = element.id if element
  args[:distance] = distance if distance
  args[:name] = name if name
  args[:toVisible] = to_visible if to_visible
  args[:predicateString] = predicate_string if predicate_string

  @driver.execute_script 'mobile: scroll', args
end

#select_picker_wheel(element:, order:, offset: nil) ⇒ Object

Parameters:

  • order (String)

    The order to move picker to. “next” or “previous”.

  • element (Element)

    Element id to perform select picker wheel on.

  • opts (Hash)

    a customizable set of options



164
165
166
167
168
169
170
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 164

def select_picker_wheel(element:, order:, offset: nil)
  return 'Set "next" or "previous" for :order' unless %w(next previous).include?(order)

  args = { element: element.id, order: order }
  args[:offset] = offset if offset
  @driver.execute_script 'mobile: selectPickerWheelValue', args
end

#swipe(direction:, element: nil) ⇒ Object

Parameters:

  • direction (string)

    Either ‘up’, ‘down’, ‘left’ or ‘right’.

  • opts (Hash)

    a customizable set of options



25
26
27
28
29
30
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 25

def swipe(direction:, element: nil)
  args = { direction: direction }
  args[:element] = element.id if element

  @driver.execute_script 'mobile: swipe', args
end

#touch_and_hold(x: nil, y: nil, element: nil, duration: 1.0) ⇒ Object

Parameters:

  • x (float) (defaults to: nil)

    Screen x long tap coordinate of type float. Mandatory parameter only if element is not set

  • y (float) (defaults to: nil)

    Screen y long tap coordinate of type float. Mandatory parameter only if element is not set

  • duration (Float) (defaults to: 1.0)

    The float duration of press action in seconds. Mandatory parameter

  • opts (Hash)

    a customizable set of options



99
100
101
102
103
104
105
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 99

def touch_and_hold(x: nil, y: nil, element: nil, duration: 1.0)
  return 'Set x, y or element' if (x.nil? || y.nil?) && element.nil?

  args = element.nil? ? { x: x, y: y } : { element: element.id }
  args[:duration] = duration
  @driver.execute_script 'mobile: touchAndHold', args
end

#two_finger_tap(element:) ⇒ Object

Parameters:

  • element (Element)

    Element to long tap on.

    “‘ruby two_finger_tap element: find_element(:accessibility_id, “some item”) “`



112
113
114
115
# File 'lib/appium_lib/ios/xcuitest/command/gestures.rb', line 112

def two_finger_tap(element:)
  args = { element: element.id }
  @driver.execute_script 'mobile: twoFingerTap', args
end