我正在尝试在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文件,但这也不起作用。有什么建议 ?
答案 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)