Search code examples
iosui-automationios-ui-automation

UIAutomation : Change location when the app is in background


I am working on UIAutomation. I need to change the location when the app is in background. I have tried following line of code:

var target = UIATarget.localTarget();
UIATarget.localTarget().deactivateAppForDuration(30);
target.setLocation({longitude:77.50, latitude:12.50});

but target.setLocation is not getting called until the app comes to foreground.

Could any one please tell me how I can change the location when the app is in background.


Solution

  • 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.

    1. Find an appropriate GPX file, preferably one that is a track.
    2. 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.
    3. Run your application from Xcode.
    4. ...
    5. Profit!