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

标签 ios mkannotation mkannotationview uitest mkuserlocation

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

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

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

会返回它,但 [that code].exists 返回 false。打印 debugDescription of otherElements 会列出 map 上的一整套注释,但不会列出用户位置。

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

最佳答案

使用可访问性标签访问您的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/

相关文章:

ios - Safari iOS13 iPad 上的全屏 PWA 具有带阅读器的 URL 栏和 "Done"按钮,无法隐藏

iphone - 具有重叠单元格的自定义单元格

ios - 自定义 MKAnnotation 类

objective-c - 如何在 MKMapView 中的 MKOverlay 上方显示 MKAnnotation

ios - 按下按钮时在 map View 上显示注释图钉

ios - 使用 cocoapods-1.0.1 下载时 Coreplot 抛出错误

ios - 设置 UICollectionViewDelegateFlowLayout Xamarin iOS F#

ios - 如何将路线时间显示为谷歌地图

swift - 如何使用 MKAnnotationView 创建圆形图像

iphone - MKAnnotationView 并将数据传递给另一个函数