gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 00:09:58 24 4
gpt4 key购买 nike

我正在努力确定如何判断 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com