10

my app is using location services, and for automated testing, I want to be able to dismiss the "APP Would Like To Use Your Current Location" popup. However, when I try to do this in Instruments with a UIAutomation script, I get this error:

Fail: Could not start script, target application is not frontmost.

This kind of makes sense, because the alert is produced by a different process. But still, what is Apple's plan for helping people automate their tests in this situation?

Richard Slater
  • 6,313
  • 4
  • 53
  • 81
Asking One
  • 161
  • 4

3 Answers3

1
**Try**

UIATarget.onAlert = function onAlert(alert)
        {
        return true;
        }
alertTitle = target.frontMostApp().alert().name();
if(alertTitle==="APP Would Like To Use Your Current Location")
{
target.frontMostApp().alert().buttons()["OK"].tap();
}
Sanjay
  • 97
  • 4
0

The solution appears to be to use AppleScript, run after a sufficient delay to allow for the alert to appear. You tell it to click on the alert button in the window of the Simulator.

Asking One
  • 161
  • 4
0

Use this code before you trigger the appearance of the Location request dialog. Note the special quotation marks around the app name.

UIATarget.onAlert = function onAlert(alert)
{
    if( alert.name()=="“local” Would Like to Use Your Current Location" )
    {
        alert.buttons()["OK"].tap();
    }
    else
    {
        UIALogger.logFail( "Location request dialog expected.");
    }
    return true;
}
bert
  • 1,556
  • 13
  • 15