2016-12-14 5 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

私はIBOutletをMKMapViewに使用しています。私がアクセスしようとすると「Mapと一致するものが見つかりません」というメッセージが表示されます。app.maps.element.otherElements ["Pin 1"] –

3

残念ながら、注釈ビューはmapsにありません。その代わりに関心のある地図ポイントがあります。注釈ビューを照会するには、XCUIApplication().windows.element.otherElements["Custom Identifier"]を使用する必要があります。

アノテーションにaccessibilityIdentifier = "Custom Identifier"を追加します。ビュー、注釈ではありません。 MKAnnotationaccessibilityIdentifierを実装していません。

+0

'app.otherElements [" Custom Identifier "]' – onmyway133

関連する問題