简体   繁体   中英

iOS emulator location for UITesting

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 ?

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

If you want custom location in your simulator then Select simulator and follor these two steps. 在此输入图像描述

在此输入图像描述

and change location

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM