private func acceptPermissionAlert() {
_ = addUIInterruptionMonitor(withDescription: "") { alert -> Bool in
if alert.buttons["Don’t Allow"].exists { //doesnt get here second time
alert.buttons.element(boundBy: 1).tapWhenExists()
return true
}
return false
}
}
这不适用于:
在应用程序的开始阶段,它在接受通知权限时工作得很好,但在这里,它不起作用。为什么是这样?
我发现addUIInterruptionMonitor
有时无法及时处理警报,或者直到测试完成为止。如果它不起作用,请尝试使用 Springboard,它管理 iOS 主屏幕。您可以从那里访问警报、按钮等,这对于您确切知道警报何时显示的测试特别有用。
所以,像这样:
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let alertAllowButton = springboard.buttons.element(boundBy: 1)
if alertAllowButton.waitForExistence(timeout: 5) {
alertAllowButton.tap()
}
The buttons.element(boundBy:1)
将确保您点击右侧的按钮,将 1 更改为 0 以点击左侧,(因为有时 '"Don't Allow"
导致问题)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)