我想在UITest中使用我的XCTestCase来点击MKAnnotationView,所以我有一个XCUIElement作为我的mapView。我不知道如何从mapView获取注释,我不想把它放在屏幕上的固定位置,因为它在各种设备上进行了测试。所以我被let mapView:XCUIElement = app.maps.elementBoundByIndex(0)卡住了
有什么想法吗?
发布于 2016-06-06 18:55:54
要与地图注释交互,请使用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()https://stackoverflow.com/questions/37652399
复制相似问题