ios - 与照片相关的警报不会调用 addUIInterruptionMonitor 的处理程序

标签 ios swift xcode-ui-testing

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
    }
}

这不适用于:

enter image description here

在应用程序的开头,它在接受通知权限时运行良好,但在这里...不起作用。

你知道为什么吗?

最佳答案

我发现 addUIInterruptionMonitor 有时不能及时处理警报,或者直到测试完成。如果它不起作用,请尝试使用管理 iOS 主屏幕的 Springboard。您可以从那里访问警报、按钮等,这对于您确切知道警报何时显示的测试特别有用。

所以,像这样:

`let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") 

let alertAllowButton = springboard.buttons.element(boundBy: 1)
if alertAllowButton.waitForExistence(timeout: 5) {
   alertAllowButton.tap()
}`

buttons.element(boundBy:1) 将确保您点击右侧的按钮,将 1 更改为 0 以点击左侧,(因为有时 “Don”中的 ' t 允许” 导致问题)。

关于ios - 与照片相关的警报不会调用 addUIInterruptionMonitor 的处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39973904/

相关文章:

xcode-ui-testing - 如何在Xcode中的UITest之间使应用保持打开状态

xcode - 识别选定状态 Swift UI 测试

ios - 如何在 UI 测试期间在 Swift 应用程序中隐藏键盘

ios - 如何传递一个额外的参数

ios - Swift:UIView.animate 工作意外

iphone - 在未(尚未)发布的游戏中测试成就

ios - 属性字符串仅更改字体大小,不更改字体名称

ios - 在同一个 Storyboard 中重用另一个表 VC 中的单元格

iphone - 3.5寸开发的ios应用改成4寸添加@2x启动图后按钮位置不对

ios - 从 Swift 字典分配 UITableView 单元格标签文本