lib/calabash-android/operations.rb in calabash-android-0.3.8 vs lib/calabash-android/operations.rb in calabash-android-0.4.0.pre1

- old
+ new

@@ -51,10 +51,14 @@ def wake_up default_device.wake_up() end + def clear_app_data + default_device.clear_app_data + end + def start_test_server_in_background default_device.start_test_server_in_background() end def shutdown_test_server @@ -90,18 +94,20 @@ raise e end end def query(uiquery, *args) - raise "Currently queries are only supported for webviews" unless uiquery.start_with? "webView" - - uiquery.slice!(0, "webView".length) - if uiquery =~ /(css|xpath):\s*(.*)/ - r = performAction("query", $1, $2) - JSON.parse(r["message"]) + if uiquery.start_with? "webView" + uiquery.slice!(0, "webView".length) + if uiquery =~ /(css|xpath):\s*(.*)/ + r = performAction("query", $1, $2) + JSON.parse(r["message"]) + else + raise "Invalid query #{uiquery}" + end else - raise "Invalid query #{uiquery}" + JSON.parse(http("/query", {"query" => uiquery})) end end def ni raise "Not yet implemented." @@ -296,10 +302,15 @@ retriable :tries => 10, :interval => 1 do raise "Could not remove the keyguard" if keyguard_enabled? end end + def clear_app_data + cmd = "#{adb_command} shell am instrument sh.calaba.android.test/sh.calaba.instrumentationbackend.ClearAppData" + raise "Could not clear data" unless system(cmd) + end + def start_test_server_in_background raise "Will not start test server because of previous failures." if Cucumber.wants_to_quit if keyguard_enabled? wake_up @@ -369,13 +380,25 @@ sleep 5 raise(msg) end def touch(uiquery,options={}) - ni + if uiquery.instance_of? String + elements = query(uiquery, options) + raise "No elements found" if elements.empty? + element = elements.first + else + element = uiquery + end + + performAction("touch_coordinate", element["frame"]["x"], element["frame"]["y"]) end + def http(options, data=nil) + default_device.http(options, data) + end + def html(q) query(q).map {|e| e['html']} end def set_text(uiquery, txt) @@ -478,14 +501,9 @@ end def map( query, method_name, *method_args ) ni end - - def http(options, data=nil) - ni - end - def url_for( verb ) ni end