Class: Appium::MultiTouch

Inherits:
Object show all
Defined in:
lib/appium_lib/device/multi_touch.rb

Overview

MultiTouch actions allow for multiple touches to happen at the same time, for instance, to simulate multiple finger swipes.

Create a series of touch actions by themselves (without a ‘prepare()`), then add to a new MultiTouch action. When ready, call `prepare()` and all actions will be executed simultaneously.

“‘ruby action_1 = TouchAction.new.press(x: 45, y: 100).wait(5).release action_2 = TouchAction.new.tap(element: el, x: 50, y:5, count: 3)

multi_touch_action = MultiTouch.new multi_touch_action.add action_1 multi_touch_action.add action_2 multi_touch_action.perform

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMultiTouch

Create a new multi-action



169
170
171
# File 'lib/appium_lib/device/multi_touch.rb', line 169

def initialize
  @actions = []
end

Instance Attribute Details

#actionsObject (readonly)

self



166
167
168
# File 'lib/appium_lib/device/multi_touch.rb', line 166

def actions
  @actions
end

Class Method Details

.pinch(percentage = 25, auto_perform = true) ⇒ Object

Convenience method for pinching the screen. Places two fingers at the edges of the screen and brings them together. “‘ruby action = pinch 75 #=> Pinch the screen from the top right and bottom left corners action.perform #=> to 25% of its size. “`



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/appium_lib/device/multi_touch.rb', line 28

def pinch(percentage = 25, auto_perform = true)
  raise ArgumentError("Can't pinch to greater than screen size.") if percentage > 100

  rate = Float(percentage) / 100

  if $driver.automation_name_is_xcuitest?
    top, bottom = pinch_for_xcuitest(rate)
  elsif $driver.device_is_android?
    top, bottom = pinch_android(rate)
  else
    top, bottom = pinch_ios(rate)
  end

  pinch = MultiTouch.new
  pinch.add top
  pinch.add bottom
  return pinch unless auto_perform
  pinch.perform
end

.zoom(percentage = 200, auto_perform = true) ⇒ Object

Convenience method for zooming the screen. Places two fingers at the edges of the screen and brings them together. “‘ruby action = zoom 200 #=> Zoom in the screen from the center until it doubles in size. action.perform “`



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/appium_lib/device/multi_touch.rb', line 57

def zoom(percentage = 200, auto_perform = true)
  raise ArgumentError("Can't zoom to smaller then screen size.") if percentage < 100

  rate = 100 / Float(percentage)

  if $driver.automation_name_is_xcuitest?
    top, bottom = zoom_for_xcuitest(rate)
  elsif $driver.device_is_android?
    top, bottom = zoom_android(rate)
  else
    top, bottom = zoom_ios(rate)
  end

  zoom = MultiTouch.new
  zoom.add top
  zoom.add bottom
  return zoom unless auto_perform
  zoom.perform
end

Instance Method Details

#add(chain) ⇒ Object

Add a touch_action to be performed



175
176
177
# File 'lib/appium_lib/device/multi_touch.rb', line 175

def add(chain)
  @actions << chain.actions
end

#performObject

Ask Appium to perform the actions



180
181
182
183
# File 'lib/appium_lib/device/multi_touch.rb', line 180

def perform
  $driver.multi_touch @actions
  @actions.clear
end