1

I am trying to run my UITests on Continuous Integration server (I am using Bitrise). So in one of my UITests I have the following:

let myLocationPin = app.otherElements["My Location"]
        self.expectation(for: exists, evaluatedWith: myLocationPin, handler: nil)

        self.waitForExpectations(timeout: 20, handler: nil)

        expect(myLocationPin.exists).to(beTrue())
        expect(myLocationPin.isHittable).to(beTrue())
        myLocationPin.tap()

It works well on my local machine but as soon as the tests is being ran on the CI server it fails. I have found out that the reason is for the failure is that the emulator that runs the test doesn't have any selected location. I have tried to add a GPX file, but that didn't work either. Any suggestions ?

radioaktiv
  • 2,437
  • 4
  • 27
  • 36

2 Answers2

4

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

Community
  • 1
  • 1
Tamas Papik
  • 101
  • 4
  • Thanks for the answer. I have tried the proposed solutions but it seems like the emulator doesn't respect the selected test locations. – radioaktiv Apr 24 '17 at 13:43
  • Apparently the GPX file is not read when using `xcodebuild`: http://www.openradar.me/48748246. The lyft solution instead seems to work :) – Eugenio Sep 18 '19 at 16:00
-1

If you want custom location in your simulator then Select simulator and follor these two steps. enter image description here

enter image description here

and change location

Jagveer Singh
  • 2,258
  • 19
  • 34