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.