Detecting Paste Notification in UI Tests?

Viewed 272

I have a use case where I am exercising pasting into a text view and then navigating.

I want to know if there is a way to wait on the paste notification disappearing since it blocks interaction with elements underneath it.

Anyone have any ideas on on this? I feel like it should live off of springboard, though I haven't had luck finding it yet.

Thanks!

1 Answers

Waiting for the Paste menu item to disappear provides enough of a delay for me. Without this, my tests were failing when copying from the clipboard since, like you, things were trying to proceed before the UI was ready.

UIPasteboard.general.string = searchTerm
searchField.tap()
app.menuItems["Paste"].tap()
_ = app.menuItems["Paste"].waitForDisappearance()

and then waitForDisappearance is a pretty standard expectation waiting function that extends XCUIElement:

func waitForDisappearance(timeout: TimeInterval = 2.0) -> Bool {
    let expectation = XCTNSPredicateExpectation(predicate: NSPredicate(format: UIStatus.notExist.rawValue),
                                                object: self)
    let result = XCTWaiter.wait(for: [expectation], timeout: timeout)
    switch result {
    case .completed:
        return true
    default:
        return false
    }
}

Sometimes I do something with the result, but most often I throw it away.

Related