Dismiss a SFSafariViewController in a Calabash test
Posted: | Author: Jörn | Filed under: Calabash, iOS, UITests | Tags: SFSafariViewController | 1 Comment »When writing a Calabash test for a new feature I encountered the following challenge: During the test a SFSafariViewController is presented and has to be dismissed again. For security reasons the user’s activity and interaction with SFSafariViewController are not visible to the app. In other words: Calabash cannot access the SFSafariViewController’s UI elements via query.
So you cannot query the ‘Done’ button like this:
def doneButton
"view:'_UIModernBarButton' marked:'Done'"
end
Because SFSafariViewController’s ‘Done’ Button is not accessible for the app, Calabash cannot see it and the test fails.
Calabash added a DeviceAgent for that case. The DeviceAgent can detect views that are outside of your own app or views that are presented by the OS (like SFSafariViewController or MFMailComposeViewController).
So to tap the SFSafariViewController’s ‘Done’ button and dismiss it you can do this:
Then(/^I close Safari/) do
device_agent.touch(type: 'Button', marked: 'Done')
end
You can also use this to dismiss an Email Compose View Controller (Although there you have to touch the ‘Cancel’ button).
Just be aware that you should use the DeviceAgent when you really have to, because Calabash’s query engine is faster and can find more views than the DeviceAgent.
1
This is my first message here and I’m glad I found this community. I’ve already picked up a few useful tips just from browsing existing posts which definitely says a lot about the value of the discussions. It’s great to see people open to share what’s worked for them and explain things in a way that’s easy to understand. I’m looking forward to continuing to learn. I have recently been reading about this lately.