问题描述
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中打印一条语句时,它不会打印,这使我认为该块未触发。
解决方法
尽管这不能解决当前的问题,但我发现了一种解决方法: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()
}