我想使用我的 XCTestCase
和 UITest 来点击 MKAnnotationView
,所以我将我的 mapView 作为 XCUIElement
。我不知道如何从 mapView 获取注释,我不想在屏幕上放置固定位置,因为它在各种设备上进行了测试。所以我被困在
让mapView:XCUIElement = app.maps.elementBoundByIndex(0)
有什么想法吗?
最佳答案
要与 map 注释交互,请使用 title
属性引用的 otherElements
。
例如,在您的生产代码中,在 MKAnnotation
中设置标题。
class Annotation: NSObject, MKAnnotation {
let coordinate: CLLocationCoordinate2D
let title: 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)
let mapView = MKMapView()
mapView.addAnnotation(annotation)
然后在测试中,您可以通过其 title
属性引用注释。
let app = XCUIApplication()
let annotation = app.maps.element.otherElements["BeerMenus HQ"]
annotation.tap()
关于ios - 使用 XCTestCase 点击 MKAnnotationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37652399/