How to Use Gpx File for UI Tests Only

iOS emulator location for UITesting

Did you select location on your local machine from the dropdown list before run?

If it is the case then you won't be able to use the graphical UI to do it on bitrise, however locations can be selected per scheme.

You can follow this post to set location on your schemes:
Automating Xcode' Debug > Simulate Location command

Update:

If the method above didn't solved the issue, another solution would be:

To change location in the simulator itself, you will need to add a script step before your UITest including the following script:

# download set-simulator-location
brew install lyft/formulae/set-simulator-location

# run simulator
export IOS_SIMULATOR_UDID=`instruments -s devices | grep "iPhone 6 (10.3) \[" | awk -F '[ ]' '{print $4}' | awk -F '[\[]' '{print $2}' | sed 's/.$//'`
echo $IOS_SIMULATOR_UDID
open -a "simulator" --args -CurrentDeviceUDID $IOS_SIMULATOR_UDID

# wait simulator to start fully
sleep 15

# set location
set-simulator-location -q London

Don't forget to change iPhone 6 (10.3) to the simulator you need and London to your own location, with -c flag you can set coordinates as well.

For more info about set-simulator-location visit: set-simulator-location

GPX files for iOS Simulator

You create a route and generate a gpx file here - http://www.bikehike.co.uk/mapview.php

On another note it might help, are you aware the simulator can simulate movement if you run the simulator then select the following menu options:

  • Debug
  • Location
  • You can select freeway drive, cycle ride, run etc

Change Simulator Location using Xcode's UITesting

Found another question similar to this one so thought I would reuse the answer I just posted there:

"I think the best approach to this will be to use GPX files. These allow you to set the lat and long of a location. (For more details see here: https://blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html)

However, I suspect you will need to call these from within the app itself and then use UI testing launch arguments (when you launch XCUIApplication) to stipulate which GPX files to use depending upon the test."

Programmatically simulate GPS location in iOS tests

I have had similar problems when writing UI tests, because the simulator / tethered device can't do everything you might want. What I do is write mocks that mimic the desired behavior (of something I would normally have no control over).

Substituting a custom location manager for the CLLocationManager will allow you to take full control of location updates, as you can programmatically send the location updates through the CLLocationManagerDelegate method: locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]).

Create a class MyLocationManager, make it a subclass of CLLocationManager, and have it override all the methods you call. Don't call super in the overridden methods, as CLLocationManager should never actually receive a method call.

class MyLocationManager: CLLocationManager {
override func requestWhenInUseAuthorization() {
// Do nothing.
}

override func startUpdatingLocation() {
// Begin location updates. You can use a timer to regularly send the didUpdateLocations method to the delegate, cycling through an array of type CLLocation.
}

// Override all other methods used.

}

The delegate property doesn't need to be overridden (and can't be), but you have access to it as a subclass of CLLocationManager.

To use MyLocationManager you should pass in launch arguments that tell your app if it is a UITest or not. In your test case's setUp method insert this line of code:

app.launchArguments.append("is_ui_testing")

Store CLLocationManager as a property that is a MyLocationManager when testing. When not testing CLLocationManager will be used as normal.

static var locationManger: CLLocationManager = ProcessInfo.processInfo.arguments.contains("is_ui_testing") ? MyLocationManager() : CLLocationManager()


Related Topics



Leave a reply



Submit