2016-12-14 7 views
0

XCTest의 UI 테스트를 통해 MKMapView의 핀에 액세스하려면 어떻게해야합니까?XCTest UI 테스트를 통한 MKAnnotation

나는, 수를 계산 특정 사람 등, (접근성 ID 또는 제목에 따라)

이 MKAnnotation에 대한 XCUIElementType있을없는 것입니다 확인합니다.

MKMapView + XCTest에서 문서를 찾는 데 어려움을 겪고 있습니다.

답변

2

UIAccessibilityIdentification을 사용하십시오.

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.2853, -73.3382) 
let annotation = Annotation(title: "A Place Title", coordinate: coordinate) 
annotation.accessibilityIdentifier = "Some Identifier" 
let mapView = MKMapView() 
mapView.addAnnotation(annotation) 

테스트에서 당신은 otherElements를 통해 주석을 참조 할 수 있습니다.

let app = XCUIApplication() 
let annotation = app.maps.element.otherElements["Custom Identifier"] 
annotation.tap() 
+0

MKMapView에 IBOutlet을 사용하고 있습니다. app.caps.element.otherElements [ "Pin 1"] –

3

불행히도 주석보기는 maps이 아닙니다. 그 대신 관심있는지도 점을 찾을 수 있습니다. 주석보기를 쿼리하려면 XCUIApplication().windows.element.otherElements["Custom Identifier"]을 사용해야합니다.

주석에 accessibilityIdentifier = "Custom Identifier"을 추가하십시오. 보기, 주석이 아닙니다. MKAnnotationaccessibilityIdentifier을 구현하지 않습니다.

+0

'app.otherElements [ "Custom Identifier"]'를 사용하면 XCTest가 "Map에 일치하는 항목이 없습니다."라고 알려줍니다. – onmyway133