以下测试在 iOS 11 上运行良好。它消除了请求权限使用位置服务的警报,然后放大 map 。在 iOS 10 或 9 上,它什么都不做,测试仍然成功
func testExample() {
let app = XCUIApplication()
var handled = false
var appeared = false
let token = addUIInterruptionMonitor(withDescription: "Location") { (alert) -> Bool in
appeared = true
let allow = alert.buttons["Allow"]
if allow.exists {
allow.tap()
handled = true
return true
}
return false
}
// Interruption won't happen without some kind of action.
app.tap()
removeUIInterruptionMonitor(token)
XCTAssertTrue(appeared && handled)
}
有没有人知道原因和/或解决方法?
这是一个可以重现问题的项目:https://github.com/TitouanVanBelle/Map
更新
Xcode 9.3 Beta 的变更日志显示如下
XCTest UI interruption monitors now work correctly on devices and simulators running iOS 10. (33278282)
最佳答案
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let allowBtn = springboard.buttons["Allow"]
if allowBtn.waitForExistence(timeout: 10) {
allowBtn.tap()
}
更新.exists
为.waitForExistence(timeout: 10)
,详情请查看评论。
关于ios - addUIInterruptionMonitor(withDescription :handler:) not working on iOS 10 or 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45228343/