5

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.

carlossless
  • 1,171
  • 8
  • 23

3 Answers3

2

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
Shaun
  • 412
  • 2
  • 7
  • Your assumption is correct, however I would still like to have the ability to execute my tests on a real device at some time. But either way could you give me an example of this ui script? – carlossless Dec 19 '12 at 11:45
  • Let me know if that apple script works for you, I tried it on on my iPhone simulator and it dismissed the alert with no problems. – Shaun Dec 19 '12 at 22:06
1

It is indeed possible to interact with this alert. All alerts that show up while your app is running can be handled by assigning an onAlert handler before you trigger it.

Based on the question you asked, it sounds like you're firing up the CLLocationManager immediately on app launch. If possible, try to delay it by a half second or so. Then, in your UI Automation script, you can immediately assign an alert handler right at the beginning. Something like this:

UIATarget.onAlert = function(alert) {
    alert.defaultButton().tap();
    return true;
};

That tells the alert to tap the default (confirmation) button and the return true tells the alert handling mechanism that we handled it. If you returned false, then the system would think it needs to tap the cancel button (which is the default behavior).

Hope that helps!

Jonathan Penn
  • 1,341
  • 7
  • 8
  • Nope, still getting App not frontmost errors. Trying to manually get around this causes random crashes within instruments. – carlossless Dec 19 '12 at 12:50
0

Above solution that embeds applescript script into cucumber script

Given /^I am on the GPS permission screen$/ do
IO.popen("osascript", "w") do |f|
# applescript to OK sharing of Current Location
f.puts <<-eos
    tell application "iPhone Simulator"
        activate
    end tell

    tell application "System Events"
        tell process "iPhone Simulator"
            repeat
                try
                    click button "OK" of window 1
                    exit repeat
                end try
            end repeat
        end tell
    end tell
eos

end end

Jambi
  • 21
  • 2