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

调试告诉我MKUserLocation注释实例的标题为“我的位置”。我期望以下方法会起作用:

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


将返回它,但是[那个代码] .exists返回false。打印otherElements的debugDescription会在地图上列出整个注释集,但不会列出用户位置。

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

最佳答案

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

yourAnnotation.accessibilityLabel = "labelYouWillUseToFindIt"


然后在测试期间,您可以执行以下操作:

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


使用print(app.debugDescription)来查看您的注释是否可见,如果不可见,请通过以下方式强制对其进行访问:

yourAnnotation.isAccessibilityElement = true


您可以阅读有关辅助功能标签here的更多信息

关于ios - 在iOS UI测试中,如何识别MKUserLocation批注?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46759246/

10-12 01:29