【问题标题】:In iOS UI Testing, how do I identify the MKUserLocation annotation?在 iOS UI 测试中,如何识别 MKUserLocation 注解?
【发布时间】:2017-10-15 19:41:51
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: ios mkannotation mkannotationview uitest mkuserlocation


    【解决方案1】:

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

    yourAnnotation.accessibilityLabel = "labelYouWillUseToFindIt"
    

    那么在你的测试中你可以做:

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

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

    yourAnnotation.isAccessibilityElement = true
    

    你可以阅读更多关于无障碍标签here

    【讨论】:

    • 谢谢哈维尔。将可访问性标签添加到注释视图后,我实际上可以在调试描述中看到它。它实际上是可以通过 app.otherElements["Current Location"] 而不是通过 app.maps....
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多