Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for managing SpringBoard alerts manually #611

Merged
merged 4 commits into from
Mar 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions lib/run_loop/device_agent/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,47 @@ 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
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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down