简体   繁体   English

用于UITesting的iOS模拟器位置

[英]iOS emulator location for UITesting

I am trying to run my UITests on Continuous Integration server (I am using Bitrise). 我试图在持续集成服务器上运行我的UITests(我正在使用Bitrise)。 So in one of my UITests I have the following: 所以在我的一个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()

It works well on my local machine but as soon as the tests is being ran on the CI server it fails. 它在我的本地计算机上运行良好,但只要在CI服务器上运行测试就会失败。 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. 我试图添加一个GPX文件,但这也不起作用。 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. 如果是这种情况,那么您将无法使用图形UI在bitrise上执行此操作,但是可以根据方案选择位置。

You can follow this post to set location on your schemes: Automating Xcode' Debug > Simulate Location command 您可以按照此帖子在您的方案上设置位置: 自动执行Xcode的“调试”>“模拟位置”命令

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: 要更改模拟器本身的位置,您需要在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

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. 不要忘记将iPhone 6 (10.3)更改为您需要的模拟器,将London更改为您自己的位置,使用-c标志也可以设置坐标。

For more info about set-simulator-location visit: set-simulator-location 有关set-simulator-location更多信息,请访问: set-simulator-location

If you want custom location in your simulator then Select simulator and follor these two steps. 如果您想在模拟器中自定义位置,请选择模拟器,然后按这两个步骤操作。 在此输入图像描述

在此输入图像描述

and change location 并改变位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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