override func setUp() {
addUIInterruptionMonitor(withDescription: "App store alert") { (alert) -> Bool in
alert.buttons.element(boundBy: 0).tap()
return true
}
}
func test() {
functionThatCausesAlertToAppear()
XCUIApplication().tap()
}
当我尝试在 addUIInterruptionMonitor 中打印一条语句时,它不会打印,这让我相信该 block 没有被触发。
最佳答案
虽然这不能解决当前的问题,但我找到了解决方法:addUIInterruptionMonitor(withDescription:handler:) not working on iOS 10 or 9
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let allowBtn = springboard.buttons["Allow"]
if allowBtn.waitForExistence(timeout: 10) {
allowBtn.tap()
}
关于alert - XCUItest addUIInterruptionMonitor 未捕获 iOS14 模拟器和 xcode 12 上的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64126492/