swiftswift3xcode-ui-testing

How do I click on an edit menu using UITest and Swift 3


In my UITest I can long-press in a textview which pops up an edit menu with the two options Select and Select All. How do I choose one of these? Here is my code and it fails on the third line.

app.textViews["noteText"].tap()
app.textViews["noteText"].press(forDuration: 2)
app.staticTexts["Select All"].tap()

Solution

  • Swift 2.3 answer: app.descendantsMatchingType(.Any).elementMatchingType(.Any, identifier: "Select All")

    Swift 3 answer: app.descendants(matching: .any).element(matching: .any, identifier: "Select All").tap()

    It's not clear why different queries return different results, but this query consistently returns the maximal superset of all queries in my experience and can be used whenever an identifier is globally unique across the view hierarchy.