lib/calabash-android/operations.rb in calabash-android-0.4.19.pre3 vs lib/calabash-android/operations.rb in calabash-android-0.4.19.pre4
- old
+ new
@@ -699,26 +699,44 @@
screenshot_embed
end
raise(msg)
end
- def touch(uiquery,*args)
- raise "Cannot touch nil" unless uiquery
+ def double_tap(uiquery, options = {})
+ center_x, center_y = find_coordinate(uiquery)
+ performAction("double_tap_coordinate", center_x, center_y)
+ end
+
+ def long_press(uiquery, options = {})
+ center_x, center_y = find_coordinate(uiquery)
+
+ performAction("long_press_coordinate", center_x, center_y)
+ end
+
+ def touch(uiquery, options = {})
+ center_x, center_y = find_coordinate(uiquery)
+
+ performAction("touch_coordinate", center_x, center_y)
+ end
+
+ def find_coordinate(uiquery)
+ raise "Cannot find nil" unless uiquery
+
if uiquery.instance_of? String
- elements = query(uiquery, *args)
+ elements = query(uiquery)
raise "No elements found. Query: #{uiquery}" if elements.empty?
element = elements.first
else
element = uiquery
element = element.first if element.instance_of?(Array)
end
-
center_x = element["rect"]["center_x"]
center_y = element["rect"]["center_y"]
- performAction("touch_coordinate", center_x, center_y)
+
+ [center_x, center_y]
end
def http(path, data = {}, options = {})
default_device.http(path, data, options)
end
@@ -726,15 +744,16 @@
def html(q)
query(q).map {|e| e['html']}
end
def set_text(uiquery, txt)
- raise "Currently queries are only supported for webviews" unless uiquery.start_with? "webView"
- uiquery.slice!(0, "webView".length)
- if uiquery =~ /(css|xpath):\s*(.*)/
+ view,arguments = uiquery.split(" ",2)
+ raise "Currently queries are only supported for webviews" unless view.downcase == "webview"
+
+ if arguments =~ /(css|xpath):\s*(.*)/
r = performAction("set_text", $1, $2, txt)
else
- raise "Invalid query #{uiquery}"
+ raise "Invalid query #{arguments}"
end
end
def swipe(dir,options={})