From 3774d74e90a02ecd3fddaf1528a3686a7cb83443 Mon Sep 17 00:00:00 2001 From: Joshua Moody Date: Tue, 28 Feb 2017 16:56:03 +0100 Subject: [PATCH 1/4] DA:Client: add POST /dismiss-springboard-alert {button_title} --- lib/run_loop/device_agent/client.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/run_loop/device_agent/client.rb b/lib/run_loop/device_agent/client.rb index b8ed8d12..d25a5a4f 100644 --- a/lib/run_loop/device_agent/client.rb +++ b/lib/run_loop/device_agent/client.rb @@ -573,6 +573,26 @@ 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 # @see #query def query_for_coordinate(uiquery) From 31ce3b32e32bb45c51971c770b499a502e641a47 Mon Sep 17 00:00:00 2001 From: Joshua Moody Date: Tue, 28 Feb 2017 16:56:40 +0100 Subject: [PATCH 2/4] DA:Client: add interface for POST /set-dismiss-springboard-alerts-automatically --- lib/run_loop/device_agent/client.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/run_loop/device_agent/client.rb b/lib/run_loop/device_agent/client.rb index d25a5a4f..d86576e3 100644 --- a/lib/run_loop/device_agent/client.rb +++ b/lib/run_loop/device_agent/client.rb @@ -592,6 +592,19 @@ def dismiss_springboard_alert(button_title) 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 From ff229351c08a1ac56ecb7120c1880d230815de58 Mon Sep 17 00:00:00 2001 From: Joshua Moody Date: Wed, 22 Mar 2017 20:46:05 +0100 Subject: [PATCH 3/4] DA:Client: respond to GET /springboard-alert changes Route no longer returns a result key. Instead it returns a hash representation of the showing SpringBoard alert or an empty hash if no alert is showing --- lib/run_loop/device_agent/client.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/run_loop/device_agent/client.rb b/lib/run_loop/device_agent/client.rb index d86576e3..052bbb50 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 From 95b305ffee10a72a3273b52e8e7aa0a2bcc7d31d Mon Sep 17 00:00:00 2001 From: Joshua Moody Date: Wed, 22 Mar 2017 20:46:40 +0100 Subject: [PATCH 4/4] DA:Client: add wait_for and wait_for_no SpringAlert --- lib/run_loop/device_agent/client.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/run_loop/device_agent/client.rb b/lib/run_loop/device_agent/client.rb index 052bbb50..dda269e7 100644 --- a/lib/run_loop/device_agent/client.rb +++ b/lib/run_loop/device_agent/client.rb @@ -836,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 @@ -851,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)