1

In my UI tests, I need to wait for the copy/paste notification to disappear. In most tests cases notification looks:

Copy/paste notification

I tried to wait this way:

    func waitForPasteboardInfoDissappear(file: StaticString = #file, line: UInt = #line) {
        let elements = [
            "Pola pasted from PolaUITests-Runner",
            "CoreSimulatorBridge pasted from Pola",
        ].map { app.staticTexts[$0] }
        if !elements.waitForDisappear(timeout: 10) {
            XCTFail("Pasteboard info still visible", file: file, line: line)
        }

    }
extension XCUIElement {
    func waitForDisappear(timeout: TimeInterval) -> Bool {
        let result = XCTWaiter().wait(for: [waitForDisappearExpectation()],
                                      timeout: timeout)
        return result == .completed
    }

    func waitForDisappearExpectation() -> XCTestExpectation {
        let predicate = NSPredicate(format: "exists == false")
        return XCTNSPredicateExpectation(predicate: predicate, object: self)
    }
}

extension Array where Element == XCUIElement {
    func waitForDisappear(timeout: TimeInterval) -> Bool {
        let expectations = map { $0.waitForDisappearExpectation() }
        let result = XCTWaiter().wait(for: expectations,
                                      timeout: timeout)
        return result == .completed
    }
}

It works in most cases, but I use snapshot testing to verify tests, and sometimes prompt is still visible (without text)

Copy/paste notification without text

Is there any way to check if this prompt is still visible on the screen?

Wez Sie Tato
  • 1,186
  • 12
  • 33
  • Case 1: Is the paste board view created by you or by the system? If it was created by you, access it by `app.staticTexts[..]`. If it is a system generated view, access it by `XCUIApplication(bundleIdentifier: "com.apple.springboard").staticTexts[...]` Case 2: You are checking for two staticText's disappearance. You know only one staticText will present at a time. Use an UI interruption monitor in this case for better handling. – Confused Sep 17 '21 at 08:08

0 Answers0