Class: Appium::TouchAction
- Defined in:
- lib/appium_lib/device/touch_actions.rb
Overview
Perform a series of gestures, one after another. Gestures are chained together and only performed when ‘perform()` is called.
Each method returns the object itself, so calls can be chained.
“‘ruby action = TouchAction.new.press(x: 45, y: 100).wait(5).release action.perform
Constant Summary collapse
- ACTIONS =
[:move_to, :long_press, :press, :release, :tap, :wait, :perform]
- COMPLEX_ACTIONS =
[:swipe]
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
Instance Method Summary collapse
-
#cancel ⇒ Object
Does nothing, currently.
-
#initialize ⇒ TouchAction
constructor
A new instance of TouchAction.
-
#long_press(opts) ⇒ Object
Press down for a specific duration.
-
#move_to(opts) ⇒ Object
Move to the given co-ordinates.
-
#perform ⇒ Object
Ask the driver to perform all actions in this action chain.
-
#press(opts) ⇒ Object
Press a finger onto the screen.
-
#release(opts = nil) ⇒ Object
Remove a finger from the screen.
-
#swipe(opts) ⇒ Object
Convenience method to peform a swipe.
-
#tap(opts) ⇒ Object
Touch a point on the screen.
-
#wait(milliseconds) ⇒ Object
Pause for a number of milliseconds before the next action.
Constructor Details
#initialize ⇒ TouchAction
Returns a new instance of TouchAction.
28 29 30 |
# File 'lib/appium_lib/device/touch_actions.rb', line 28 def initialize @actions = [] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
26 27 28 |
# File 'lib/appium_lib/device/touch_actions.rb', line 26 def actions @actions end |
Instance Method Details
#cancel ⇒ Object
Does nothing, currently.
124 125 126 127 128 |
# File 'lib/appium_lib/device/touch_actions.rb', line 124 def cancel @actions << { action: cancel } $driver.touch_actions @actions self end |
#long_press(opts) ⇒ Object
Press down for a specific duration.
46 47 48 49 50 |
# File 'lib/appium_lib/device/touch_actions.rb', line 46 def long_press(opts) args = opts.select { |k, _v| [:element, :x, :y, :duration].include? k } args = args_with_ele_ref(args) chain_method(:longPress, args) # longPress is what the appium server expects end |
#move_to(opts) ⇒ Object
Move to the given co-ordinates.
36 37 38 39 |
# File 'lib/appium_lib/device/touch_actions.rb', line 36 def move_to(opts) opts = args_with_ele_ref(opts) chain_method(:moveTo, opts) end |
#perform ⇒ Object
Ask the driver to perform all actions in this action chain.
118 119 120 121 |
# File 'lib/appium_lib/device/touch_actions.rb', line 118 def perform $driver.touch_actions @actions self end |
#press(opts) ⇒ Object
Press a finger onto the screen. Finger will stay down until you call release.
58 59 60 61 62 |
# File 'lib/appium_lib/device/touch_actions.rb', line 58 def press(opts) args = opts.select { |k, _v| [:element, :x, :y].include? k } args = args_with_ele_ref(args) chain_method(:press, args) end |
#release(opts = nil) ⇒ Object
Remove a finger from the screen.
69 70 71 72 |
# File 'lib/appium_lib/device/touch_actions.rb', line 69 def release(opts = nil) args = args_with_ele_ref(opts) if opts chain_method(:release, args) end |
#swipe(opts) ⇒ Object
Convenience method to peform a swipe.
Note that iOS 7 simulators have broken swipe.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/appium_lib/device/touch_actions.rb', line 103 def swipe(opts) start_x = opts.fetch :start_x, 0 start_y = opts.fetch :start_y, 0 end_x = opts.fetch :end_x, 0 end_y = opts.fetch :end_y, 0 duration = opts[:duration] press x: start_x, y: start_y wait(duration) if duration move_to x: end_x, y: end_y release self end |
#tap(opts) ⇒ Object
Touch a point on the screen
80 81 82 83 84 85 |
# File 'lib/appium_lib/device/touch_actions.rb', line 80 def tap(opts) opts[:count] = opts.delete(:fingers) if opts[:fingers] opts[:count] ||= 1 args = args_with_ele_ref opts chain_method(:tap, args) end |
#wait(milliseconds) ⇒ Object
Pause for a number of milliseconds before the next action
89 90 91 92 |
# File 'lib/appium_lib/device/touch_actions.rb', line 89 def wait(milliseconds) args = { ms: milliseconds } chain_method(:wait, args) end |