Class: Appium::TouchAction

Inherits:
Core::TouchAction
  • Object
show all
Defined in:
lib/appium_lib/common/touch_actions.rb

Overview

Perform a series of gestures, one after another. Gestures are chained together and only performed when `perform()` is called. Default is conducted by global driver.

Each method returns the object itself, so calls can be chained.

Or each methods can call without `TouchAction.new` as the following. In this case, `perform` is called automatically.

If you'd like to perform the chain with an arbitrary driver:

Examples:


action = TouchAction.new.press(x: 45, y: 100).wait(5).release
action.perform
action = TouchAction.new.swipe(....)
action.perform

# called `swipe(...).perform` in this method.
swipe(start_x: 75, start_y: 500, offset_x: 75, offset_y: 20, duration: 500)

driver =  Appium::Driver.new(opts, false).start_driver
action = TouchAction.new(driver).press(x: 45, y: 100).wait(5).release
action.perform
action = TouchAction.new(driver).swipe(....)
action.perform

Constant Summary

COMPLEX_ACTIONS =
::Appium::Core::TouchAction::COMPLEX_ACTIONS

Instance Method Summary collapse

Constructor Details

#initialize(driver = $driver) ⇒ TouchAction



47
48
49
# File 'lib/appium_lib/common/touch_actions.rb', line 47

def initialize(driver = $driver)
  super driver
end

Instance Method Details

#swipe(opts, ele = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/appium_lib/common/touch_actions.rb', line 51

def swipe(opts, ele = nil)
  start_x  = opts.fetch :start_x, 0
  start_y  = opts.fetch :start_y, 0
  offset_x = opts.fetch :offset_x, nil
  offset_y = opts.fetch :offset_y, nil
  end_x    = opts.fetch :end_x, nil
  end_y    = opts.fetch :end_y, nil
  duration = opts.fetch :duration, 200

  if end_x || end_y
    warn '[DEPRECATION] end_x and end_y will be removed. Please use offset_x and offset_y for all platform.'
    end_x ||= 0
    end_y ||= 0

    offset_x = end_x - start_x
    offset_y = end_y - start_y
  end

  super(start_x: start_x, start_y: start_y, offset_x: offset_x, offset_y: offset_y, duration: duration, ele: ele)
end