Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with the "_APPNAME_ Would Like to Use Your Current Location" alert through UIAutomation

Ok, this is driving me nuts. I've got a little CI-build system running. And I'm doing UI testing of my application with UIAutomation. Since the application uses CoreLocation, the first time the application is launched I get a little alert asking me to confirm that I want my location tracked. This would be great and all, but the alert is not part of my own application and I can't use UIAutomation to interface with it. Is there any solution to confirming this alert without manual taping of the button.

Thanks.

P.S. Getting rid of CoreLocation for a test build is not an option.

like image 887
carlossless Avatar asked Oct 21 '22 21:10

carlossless


1 Answers

The only way I have gotten around this at the previous place I worked was to write a little apple script app that can dismiss the alert for you.

You should be able to do some simple UI scripting to dismiss the alert on the iOS simulator.

Obviously I am assuming your running on the simulator and not device for your tests.

How to dismiss location alert via apple script for iPhone simulator

  1. In System Preferences open up Accessibility. In the bottom left corner make sure you check the option Enable Access for assistive devices

Apple script to run after you app has launched in the simulator and the alert is displayed so you will need to run this after some delay.

tell application "iPhone Simulator"
    activate
end tell

tell application "System Events"
    tell process "iPhone Simulator"
        click button "OK" of window 1
    end tell
end tell
like image 141
Shaun Avatar answered Oct 27 '22 14:10

Shaun