Unfortunately UIAutomation can only automate the application it's attached to. When the application is not "active", it has nothing to talk to. Using lockForDuration
, deactivateAppForDuration
, etc blocks while it relinquishes control to the system, making your app inactive. While the application is in that state UIAutomation can't send it any more messages.
I would recommend filing a radar asking for the ability to set the location while the application is inactive.
When I ran into a similar problem in the past I had to use AppleScript to change the location of the simulator to get the effect I needed.
You have since updated your comments indicating you are testing a navigation application. Well! That's a little different. If you do not ACTUALLY require UIAutomation and were only trying to use it as a way to set the location:
Xcode does allow you to simulate a route using GPX files, and this CAN be used with Instruments.
- Find an appropriate GPX file, preferably one that is a track.
- Go to the scheme for your project. In the Run action, go to the "Options" tab. Check "Allow Location Simulation" and use the drop down list to add your GPX.
- Run your application from Xcode.
- ...
- Profit!