Search code examples
swift3xcode8mkannotationxctestxcode-ui-testing

MKAnnotation via XCTest UI Testing


How can I access the pins on an MKMapView via XCTest's UI Tests?

I want to count the number, verify specific ones are there (based on accessibility id or title), etc.

There doesn't seem to be a XCUIElementType for MKAnnotation.

I'm having a hard time finding any documentation on MKMapView + XCTest.


Solution

  • The annotation views aren't under maps unfortunately. You will find map points of interest there instead. To query for an annotation view you should use XCUIApplication().windows.element.otherElements["Custom Identifier"].

    Add the accessibilityIdentifier = "Custom Identifier" to your annotation view, not annotation. MKAnnotation doesn't implement accessibilityIdentifier.