2

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!

nomad00
  • 401
  • 3
  • 10
  • Do you happen to be pasting via the UI `Paste` button? If so I have one test doing that where I wait for that button to disappear before proceeding. If you're pasting programmatically, I don't have any ideas for you. – Mike Collins May 26 '21 at 16:29
  • Good suggestion @MikeCollins, though the `Paste` button disappears notably before the notification does. Thanks though! – nomad00 May 26 '21 at 19:09
  • Waiting for it works for me :shrug: I'll share my code below. – Mike Collins May 27 '21 at 16:04
  • Did you ever find a satisfactory solution to this? I decided to try my framework on a phone today and this is the only thing causing an issue. If I add a sleep(1) after adding my data to the pasteboard, all is well, but I hate sleeps; it'd be the only one in my codebase, but I'm not finding any way to detect this state. I could add complicated code to detect the failure and retry, but I think a sleep might be preferable because it's effectively what I'm doing, a single line of code, and very readable. – Mike Collins Dec 09 '21 at 19:49

1 Answers1

0

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.

Mike Collins
  • 4,108
  • 1
  • 21
  • 28