Sha256: 661a3404d0e08f4380e6a79101699bcd84481c34d5b1d57ac4f2bd501ce0e416

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

module Appium
  # 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.
  #
  # ```ruby
  # action = TouchAction.new.press(x: 45, y: 100).wait(5).release
  # action.perform
  # action = TouchAction.new.swipe(....)
  # action.perform
  # ```
  #
  # Or each methods can call without `TouchAction.new` as the following.
  # In this case, `perform` is called automatically.
  # ```ruby
  # # called `swipe(...).perform` in this method.
  # swipe(start_x: 75, start_y: 500, offset_x: 75, offset_y: 20, duration: 500)
  # ```
  #
  # If you'd like to perform the chain with an arbitrary driver:
  # ```ruby
  # driver =  Appium::Driver.new(opts, false).start_driver
  # action = TouchAction.new.press(x: 45, y: 100).wait(5).release
  # action.perform(@driver)
  # action = TouchAction.new.swipe(....)
  # action.perform(@driver)
  # ```
  class TouchAction < ::Appium::Core::TouchAction
    COMPLEX_ACTIONS = ::Appium::Core::TouchAction::COMPLEX_ACTIONS

    class << self
      COMPLEX_ACTIONS.each do |action|
        define_method(action) do |opts|
          auto_perform = opts.delete(:auto_perform) { |_k| true }
          ta           = ::Appium::TouchAction.new($driver)
          ta.send(action, opts)
          return ta unless auto_perform
          ta.perform
        end
      end
    end

    def initialize(driver = $driver)
      super driver
    end
  end # class TouchAction
end # module Appium

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
appium_lib-9.7.1 lib/appium_lib/common/touch_actions.rb
appium_lib-9.7.0 lib/appium_lib/common/touch_actions.rb