【问题标题】:XCUItest addUIInterruptionMonitor is not capturing alerts on iOS14 simulator and xcode 12XCUItest addUIInterruptionMonitor 未在 iOS14 模拟器和 xcode 12 上捕获警报
【发布时间】:2020-09-29 19:37:27
【问题描述】:
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 中打印一条语句时,它不会打印让我相信该块没有被触发。

【问题讨论】:

    标签: alert ios14 xcuitest


    【解决方案1】:

    虽然这并不能解决手头的问题,但我找到了解决方法: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()
    }
    

    【讨论】:

    • 我在使用 Xcode 12.4 和运行 iOS 14.5 beta 的实际手机时也遇到了同样的问题。我使用了相同的解决方法,它适用于某些警报,但当手机收到全屏电话时不起作用。它会检测电话是否设置为横幅。
    猜你喜欢
    • 2018-05-01
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 2019-09-04
    相关资源
    最近更新 更多