Sha256: eab05580fce7e95a860937967b88bfdcb54fe385dfafc29d15e435dcef7e260b

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

require 'calabash-android/env'
require 'calabash-android/monkey_helpers'

module Calabash
  module Android
    module DragHelpers
      include Calabash::Android::EnvironmentHelpers
      include Calabash::Android::MonkeyHelpers

      def drag_coordinates(from_x, from_y, to_x, to_y, steps=10, hold_time=0.5, hang_time=0.5)
        calabash_log "Dragging from #{from_x},#{from_y} to #{to_x},#{to_y}"
        monkey_move_from(from_x, from_y,
                         to_x, to_y,
                         hold_time: hold_time,
                         hang_time: hang_time,
                         steps: steps)
      end

      def drag_and_drop(from_query, to_query, steps=10, hold_time=0.5, hang_time=0.5)
        wait_for_element_exists(from_query)
        wait_for_element_exists(to_query)

        from_results = query(from_query)
        to_results = query(to_query)

        if from_results.any?
          if to_results.any?
            from_rect = from_results.first['rect']
            to_rect = to_results.first['rect']
            from_x = from_rect['center_x']
            from_y = from_rect['center_y']
            to_x = to_rect['center_x']
            to_y = to_rect['center_y']

            monkey_move_from(from_x, from_y, to_x, to_y, hold_time: hold_time, hang_time: hang_time, steps: steps)
          else
            raise "No matching elements for: #{to_query}"
          end
        else
          raise "No matching elements for: #{from_query}"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
calabash-android-0.9.30 lib/calabash-android/drag_helpers.rb
calabash-android-0.9.29 lib/calabash-android/drag_helpers.rb
calabash-android-0.9.28 lib/calabash-android/drag_helpers.rb
calabash-android-0.9.25 lib/calabash-android/drag_helpers.rb
calabash-android-0.9.24 lib/calabash-android/drag_helpers.rb