在我的 UI 测试中,我需要等待复制/粘贴通知消失。在大多数测试案例中,通知看起来:
我试着这样等待:
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
}
}
大多数情况下都能用,但我使用快照测试来验证测试,有时提示仍然可见(没有文字)
有什么办法可以检查这个提示是否仍然在屏幕上可见?