class Calabash::Android::Gestures::Gesture
Attributes
touches[R]
Public Class Methods
double_tap(opt={})
click to toggle source
# File lib/calabash-android/gestures.rb, line 168 def self.double_tap(opt={}) self.tap(opt).merge(self.tap({wait: 0.1}.merge(opt))) end
generate_pinch_out(from_arr, to_arr, opt={})
click to toggle source
# File lib/calabash-android/gestures.rb, line 211 def self.generate_pinch_out(from_arr, to_arr, opt={}) self.generate_swipe(from_arr[0], to_arr[0], opt) + self.generate_swipe(from_arr[1], to_arr[1], opt) end
generate_swipe(from_hash, to_hash, opt={})
click to toggle source
# File lib/calabash-android/gestures.rb, line 172 def self.generate_swipe(from_hash, to_hash, opt={}) from_params = from_hash.merge(opt).merge(opt[:from] || {}) to_params = {time: 0}.merge(to_hash).merge(opt[:to] || {}) if opt[:flick] to_params.merge!(wait: 0) else to_params = {wait: 0.2}.merge(to_params) end self.tap({release: false}.merge(from_params)).merge(self.tap(to_params)) end
generate_tap(touch_hash)
click to toggle source
# File lib/calabash-android/gestures.rb, line 152 def self.generate_tap(touch_hash) MultiTouchGesture.new(Gesture.new(Touch.new(touch_hash))) end
new(touches = [], query_string = nil)
click to toggle source
# File lib/calabash-android/gestures.rb, line 78 def initialize(touches = [], query_string = nil) unless touches.is_a?(Array) touches = [touches] end @touches = [] touches.each do |touch| @touches << Touch.new(touch) end @query_string = query_string end
pinch(direction, opt={})
click to toggle source
# File lib/calabash-android/gestures.rb, line 215 def self.pinch(direction, opt={}) opt[:from] ||= [] opt[:from][0] = (opt[:from][0] || {}).merge(opt) opt[:from][1] = (opt[:from][1] || {}).merge(opt) opt[:to] ||= [] opt[:to][0] ||= {} opt[:to][1] ||= {} from = [{x: 40, y: 40}.merge(opt[:from][0]), {x: 60, y: 60}.merge(opt[:from][1])] to = [{x: 10, y: 10}.merge(opt[:to][0]), {x: 90, y: 90}.merge(opt[:to][1])] case direction when :out when :in from,to = to,from else raise "Cannot pinch #{direction}" end generate_pinch_out(from, to) end
swipe(direction, opt={})
click to toggle source
# File lib/calabash-android/gestures.rb, line 185 def self.swipe(direction, opt={}) from = {x: 50, y: 50} to = {x: 50, y: 50} case direction when :left from[:x] = 90 to[:x] = 10 when :right from[:x] = 10 to[:x] = 90 when :up from[:y] = 90 to[:y] = 10 when :down from[:y] = 10 to[:y] = 90 else raise "Cannot swipe in #{direction}" end opt[:time] ||= 0.3 generate_swipe(from, to, opt) end
tap(opt={})
click to toggle source
# File lib/calabash-android/gestures.rb, line 156 def self.tap(opt={}) touch = opt[:touch] || {} touch[:x] ||= (opt[:x] || 50) touch[:y] ||= (opt[:y] || 50) touch[:time] ||= (opt[:time] || 0.2) touch[:release] = touch[:release].nil? ? (opt[:release].nil? ? true : opt[:release]) : touch[:release] touch[:wait] ||= (opt[:wait] || 0) touch[:offset] ||= opt[:offset] generate_tap(touch) end
with_parameters(multi_touch_gesture, params={})
click to toggle source
# File lib/calabash-android/gestures.rb, line 145 def self.with_parameters(multi_touch_gesture, params={}) multi_touch_gesture.query_string = params[:query_string] if params[:query_string] multi_touch_gesture.timeout = params[:timeout] if params[:timeout] multi_touch_gesture end
Public Instance Methods
+(gesture)
click to toggle source
# File lib/calabash-android/gestures.rb, line 109 def +(gesture) Gesture.new(@touches + gesture.touches, @query_string) end
<<(touch)
click to toggle source
# File lib/calabash-android/gestures.rb, line 118 def <<(touch) @touches << touch end
add_touch(touch)
click to toggle source
# File lib/calabash-android/gestures.rb, line 113 def add_touch(touch) touches = @touches Gesture.new(touches << touch, @query_string) end
from(touch)
click to toggle source
# File lib/calabash-android/gestures.rb, line 92 def from(touch) to(touch) end
max_execution_time()
click to toggle source
# File lib/calabash-android/gestures.rb, line 141 def max_execution_time (@touches.map {|touch| touch.wait + touch.time}).reduce(:+) end
offset=(offset)
click to toggle source
# File lib/calabash-android/gestures.rb, line 137 def offset=(offset) @touches.each {|touch| touch.offset=offset} end
query_string=(query_string)
click to toggle source
# File lib/calabash-android/gestures.rb, line 129 def query_string=(query_string) @query_string = query_string end
reset_query_string()
click to toggle source
# File lib/calabash-android/gestures.rb, line 133 def reset_query_string touches.each {|touch| touch.query_string=nil} end
to(touch)
click to toggle source
# File lib/calabash-android/gestures.rb, line 96 def to(touch) if touch.is_a?(Hash) touch = Touch.new(touch) end unless (last_touch = @touches.last).nil? touch.x ||= last_touch.x touch.y ||= last_touch.y end Gesture.new(@touches << touch, @query_string) end
to_json(*object)
click to toggle source
# File lib/calabash-android/gestures.rb, line 122 def to_json(*object) { query_string: @query_string, touches: @touches }.to_json(*object) end