用于UITesting的iOS模拟器位置

时间:2017-04-23 19:48:47

标签: ios continuous-integration xcode-ui-testing ui-testing bitrise

我正在尝试在Continuous Integration服务器上运行我的UITests(我正在使用Bitrise)。因此,在我的一个UITests中,我有以下内容:

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()

它在我的本地计算机上运行良好但是只要在CI服务器上运行测试就会失败。我发现原因是失败的原因是运行测试的模拟器没有任何选定的位置。我试图添加一个GPX文件,但这也不起作用。有什么建议 ?

2 个答案:

答案 0 :(得分:3)

在运行之前,您是否从下拉列表中选择了本地计算机上的位置?

如果是这种情况,那么您将无法使用图形用户界面在bitrise上执行此操作,但是可以根据方案选择位置。

您可以按照此信息设置您的计划的位置: Automating Xcode' Debug > Simulate Location command

<强>更新

如果上述方法没有解决问题,另一种解决方案是:

要更改模拟器本身的位置,您需要在UITest之前添加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

不要忘记将iPhone 6 (10.3)更改为您需要的模拟器并将London更改为您自己的位置,使用-c标记也可以设置坐标。

有关set-simulator-location访问权限的更多信息:set-simulator-location

答案 1 :(得分:0)

如果您想在模拟器中使用自定义位置,请选择模拟器,然后按这两个步骤操作。 enter image description here

enter image description here

并更改位置