如何解决如何在 XCUITests 中等待复制/粘贴提示消失?
在我的 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
}
}
大多数情况下都能用,但我使用快照测试来验证测试,有时提示仍然可见(没有文字)
有什么办法可以检查这个提示是否仍然在屏幕上可见?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。