在iOS UI测试中,如何识别MKUserLocation注释?

时间:2017-10-15 19:41:51

标签: ios mkannotation mkannotationview uitest mkuserlocation

我正在努力确定如何判断MKMapView是否在UI测试中显示当前用户位置引脚。这是一个MKUserLocation注释(我已经创建了一个MKAnnotationView来使用图像作为引脚而不是蓝点。)

调试告诉我MKUserLocation注释实例的标题是"我的位置"。我期待以下工作:

app.maps.element.otherElements["My Location"]

将返回它但[该代码] .exists返回false。打印其他元素的debugDescription会在地图上列出一整套注释,但不会列出用户位置。

是否有不同类型的XCUIElement表示我可以检查的pin / annotation / annotation视图?

1 个答案:

答案 0 :(得分:1)

使用辅助功能标签访问MKAnnotationView。在您的代码中,检索您的用户位置注释并为其设置辅助功能标签:

yourAnnotation.accessibilityLabel = "labelYouWillUseToFindIt"

然后在测试期间,你可以这样做:

app.maps.element.otherElements["labelYouWillUseToFindIt"]

使用print(app.debugDescription)查看您的注释是否可见,如果没有,请强制它可以通过以下方式访问:

yourAnnotation.isAccessibilityElement = true

您可以阅读有关辅助功能标签here

的更多信息