Oct*_*jas 2 xctest swift xcode-ui-testing
我正在尝试为正在使用的应用程序配置快照,该快照已经可以在英语版本中使用,但是在本地化版本中,我不知道如何为MKMapView中的地图中的图钉分配可访问性标识符怎么做呢?
谢谢。
可访问性标识符是一种将应用程序语言与Xcode UI Testing分开的好方法。标识符来自UIAccessibilityIdentification这UIView已经符合。然而,无论是NSObject也不MKAnnotation符合协议。因此,您必须自己设置一致性。
class Annotation: NSObject, MKAnnotation, UIAccessibilityIdentification {
let coordinate: CLLocationCoordinate2D
let title: String?
var accessibilityIdentifier: String?
init(title: String?, coordinate: CLLocationCoordinate2D) {
self.title = title
self.coordinate = coordinate
}
}
let coordinate = CLLocationCoordinate2DMake(40.703490, -73.987770)
let annotation = Annotation(title: "BeerMenus HQ", coordinate: coordinate)
annotation.accessibilityIdentifier = "Custom Identifier"
let mapView = MKMapView()
mapView.addAnnotation(annotation)
Run Code Online (Sandbox Code Playgroud)
然后在测试中,您可以通过引用注释otherElements。
let app = XCUIApplication()
let annotation = app.maps.element.otherElements["Custom Identifier"]
annotation.tap()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
818 次 |
| 最近记录: |