Mock iOS Simulator’s location before running UI tests from CI

Aya Akl
2 min readJun 17, 2019

--

There is a great CLI tool by Lyft that can be used to change and setting location of the iOS simulator: set-simulator-location

But we should have booted simulator running so that the tool can set the location correctly.

Once you install and setup the CLI tool, just run a shell command like:

$ set-simulator-location -c 37.7765 -122.3918

and you will see the shell answers that the simulator location has changed to the required longitude and latitude.

The tool can set the location by two ways, as per their documentation:

  1. Set a specific latitude and longitude:
$ set-simulator-location -c 37.7765 -122.3918

2. Or using place search.

$ set-simulator-location -q Lyft HQ San Francisco

We can also specify which simulator we want to change the location to because this CLI tool will change to all simulators by doing the following:

$ set-simulator-location -c 37.7765 -122.3918 -s iPhone X

So how we use it through our UI Tests:

  • We need to make sure that the location is set before our UI tests.
  • We need to make sure that the simulator is booted so that the tool can work and behave correctly.
  • We need to make sure that this is integrated to our CI.

So to enable this, please do the following (In your CI job of running UI tests):

First, we need to take a look here and use simctl which is a binary to interact with iOS simulators from command line by Apple as explained here: simctl, Control iOS Simulators from Command Line

  1. Add a task under the CI job with Shell executable.
  2. Add the following code to the shell script that would do three things:
  • Boot a simulator
  • Open the simulator
  • Set the location
  • Close the simulator
xcrun simctl boot 'iPhone 8'
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
set-simulator-location -c 37.7765 -122.3918
xcrun simctl shutdown 'iPhone 8'

3. Then call your UI tests task in the CI job to run them using the mocked location set.

This is a way only to mock simulator location before running the UI tests.

HAPPY TESTING!

Sign up to discover human stories that deepen your understanding of the world.

--

--

Aya Akl
Aya Akl

Written by Aya Akl

Author @QualityNexus || #Quality is my thing - Passionate human being who wants to change the world!!

No responses yet

Write a response