calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 369 forks source link

SFAuthenticationSession alert #1362

Open asengmany opened 6 years ago

asengmany commented 6 years ago

Hello,

Using SFAuthenticationSession show an alert that require your authorization but calabash raise en error:

Expected status code < 400, found 500.

      Server replied with:

      {"title"=>"“Account-cal” Wants to Use “****” to Sign In", "buttons"=>["Cancel", "Continue"], "tries"=>20, "error"=>"A SpringBoard alert is blocking test execution and it cannot be dismissed."}

How do we touch the Continue button without having this error?

Thanks :)

jmoody commented 6 years ago

You can manually handle this alert using something like this:

...
# Turn off automatic alert dismissal
device_agent.dismiss_springboard_alerts_manually!

# Do whatever triggers the alert, then wait for the alert
# which may or may not appear.
begin
  device_agent.wait_for_springboard_alert(10) # timeout is optional
  device_agent.dismiss_springboard_alert("Continue")
rescue RuntimeError
   # Alert did not appear, so there is nothing to do
end
...

# Turn automatic dismiss back on
dismiss_springboard_alerts_automatically!
FinHorsley commented 5 years ago

Is this work-around supported when testing locally using a physical device?

jmoody commented 5 years ago

Absolutely.

FinHorsley commented 5 years ago

How would i achieve this within the actual .cs test file? (within the test project in our solution)

FinHorsley commented 5 years ago

@jmoody Where in my UI test code to I add the code above to manually handle the alert?

jmoody commented 5 years ago

You will have to write some client code to connect to the DeviceAgent server.

The sources for the server are here:

https://github.com/calabash/DeviceAgent.iOS/blob/develop/Server/Routes

The port is 27753.

POST 1.0/set-dismiss-springboard-alerts-automatically # MetaRoute GET 1.0/spring-alert # QueryRoute POST 1.0/dismiss-springboard-alert # GestureRoute

Here is an example client in ruby:

https://github.com/calabash/run_loop/blob/develop/lib/run_loop/device_agent/client.rb#L611

Where in my UI test code to I add the code above to manually handle the alert?

You probably have some idea where, in your tests, you encounter this alert.

Before the gesture that triggers the alert, follow the pattern I showed above.

If you are encountering this problem on Test Cloud, this solution will not work because the DeviceAgent port number is not stable on Test Cloud (like it is locally).

If you are encountering this problem on Test Cloud, I will put you in touch with my manager.

If you made a pull request on DeviceAgent to automatically dismiss this alert, I would merge it.

https://github.com/calabash/DeviceAgent.iOS/blob/develop/Server/Utilities/SpringBoardAlerts.m