lib/calabash-android/operations.rb in calabash-android-0.4.0.pre1 vs lib/calabash-android/operations.rb in calabash-android-0.4.0.pre2
- old
+ new
@@ -81,20 +81,21 @@
def set_gps_coordinates(latitude, longitude)
default_device.set_gps_coordinates(latitude, longitude)
end
def wait_for(timeout, &block)
+ value = nil
begin
Timeout::timeout(timeout) do
- until block.call
+ until value = block.call
sleep 0.3
end
end
rescue Exception => e
- take_screenshot
raise e
end
+ value
end
def query(uiquery, *args)
if uiquery.start_with? "webView"
uiquery.slice!(0, "webView".length)
@@ -103,11 +104,14 @@
JSON.parse(r["message"])
else
raise "Invalid query #{uiquery}"
end
else
- JSON.parse(http("/query", {"query" => uiquery}))
+ arguments = [*args]
+ operation = {"method_name"=>"query", "arguments" => arguments}
+ data = {"query" => uiquery, "operation" => operation}
+ JSON.parse(http("/map",data))
end
end
def ni
raise "Not yet implemented."
@@ -379,19 +383,22 @@
screenshot_embed
sleep 5
raise(msg)
end
- def touch(uiquery,options={})
+ def touch(uiquery,*args)
if uiquery.instance_of? String
- elements = query(uiquery, options)
+ elements = query(uiquery, *args)
raise "No elements found" if elements.empty?
element = elements.first
else
element = uiquery
end
- performAction("touch_coordinate", element["frame"]["x"], element["frame"]["y"])
+
+ center_x = element["frame"]["x"] + element["frame"]["width"] / 2
+ center_y = element["frame"]["y"] + element["frame"]["height"] / 2
+ performAction("touch_coordinate", center_x, center_y)
end
def http(options, data=nil)
default_device.http(options, data)
end