diff --git a/lib/run_loop/device_agent/client.rb b/lib/run_loop/device_agent/client.rb index b8ed8d12..dda269e7 100644 --- a/lib/run_loop/device_agent/client.rb +++ b/lib/run_loop/device_agent/client.rb @@ -564,8 +564,7 @@ def springboard_alert request = request("springboard-alert") client = http_client(http_options) response = client.get(request) - hash = expect_300_response(response) - hash["result"] + expect_300_response(response) end # @!visibility private @@ -573,6 +572,39 @@ def springboard_alert_visible? !springboard_alert.empty? end + # @!visibility private + def dismiss_springboard_alert(button_title) + parameters = { :button_title => button_title } + request = request("dismiss-springboard-alert", parameters) + client = http_client(http_options) + response = client.post(request) + hash = expect_300_response(response) + + if hash["error"] + raise RuntimeError, %Q[ +Could not dismiss SpringBoard alert by touching button with title '#{button_title}': + +#{hash["error"]} + +] + end + true + end + + # @!visibility private + def set_dismiss_springboard_alerts_automatically(true_or_false) + if ![true, false].include?(true_or_false) + raise ArgumentError, "Expected #{true_or_false} to be a boolean true or false" + end + + parameters = { :dismiss_automatically => true_or_false } + request = request("set-dismiss-springboard-alerts-automatically", parameters) + client = http_client(http_options) + response = client.post(request) + hash = expect_300_response(response) + hash["is_dismissing_alerts_automatically"] + end + # @!visibility private # @see #query def query_for_coordinate(uiquery) @@ -804,6 +836,20 @@ def wait_for_alert(timeout=WAIT_DEFAULTS[:timeout]) end end + # @!visibility private + def wait_for_springboard_alert(timeout=WAIT_DEFAULTS[:timeout]) + options = WAIT_DEFAULTS.dup + options[:timeout] = timeout + message = %Q[ + +Timed out after #{timeout} seconds waiting for a SpringBoard alert to appear. + +] + wait_for(message, options) do + springboard_alert_visible? + end + end + # @!visibility private def wait_for_no_alert(timeout=WAIT_DEFAULTS[:timeout]) options = WAIT_DEFAULTS.dup @@ -819,6 +865,20 @@ def wait_for_no_alert(timeout=WAIT_DEFAULTS[:timeout]) end end + # @!visibility private + def wait_for_no_springboard_alert(timeout=WAIT_DEFAULTS[:timeout]) + options = WAIT_DEFAULTS.dup + options[:timeout] = timeout + message = %Q[ + +Timed out after #{timeout} seconds waiting for a SpringBoard alert to disappear. + +] + wait_for(message, options) do + !springboard_alert_visible? + end + end + # @!visibility private def wait_for_text_in_view(text, uiquery, options={}) merged_options = WAIT_DEFAULTS.merge(options)