addUIInterruption Monitor()在运行iOS 14.0.1的设备上不工作



自从将我的设备(iPhone 11(升级到iOS 14.0.1后,我发现addUIInterruption Monitor((根本不会被触发。它以前在iOS 13.4.1上运行,这是我安装的最后一个版本。

我的代码:

addUIInterruptionMonitor(withDescription: "App Would Like to Send You Notifications") { (alert) -> Bool in
if alert.buttons["Allow"].exists {
alert.buttons["Allow"].tap()
return true
}
return false
}
XCUIApplication().tap()  // interacting with the app to trigger the interruption monitor

升级后,我的代码中没有任何变化——唯一变化的是安装了iOS版本。其他人遇到过类似的情况吗?

我已经使用了以下代码:

XCUIApplication.otherElements.firstMatch.swipeLeft()

app.otherElements.firstMatch.swipeLeft()

解决方案是使用otherElements.firstMatch。不知怎的,在XCUIApplication视图层次结构中只有otherElements。您可以使用tap-事件或swipe-事件。我发现swipe-事件对UITest状态的破坏性最小。

我通过睡眠执行10s来解决它。

Darwin.sleep(10)
addUIInterruptionMonitor(withDescription: "App Would Like to Send You Notifications") { (alert) -> Bool in
if alert.buttons["Allow"].exists {
alert.buttons["Allow"].tap()
return true
}
return false
}
XCUIApplication().tap()

首先,我建议您将中断监视器放在setUp((函数中:

override func setUp() {
addUIInterruptionMonitor(withDescription: "App Would Like to Send You Notifications") { (alert) -> Bool in
if alert.buttons["Allow"].exists {
alert.buttons["Allow"].tap()
return true
}
return false
}
}

第二,如果添加睡眠对我来说解决了你的问题,这意味着这不是iOS版本的问题,而是你的应用程序在这个iOS版本上的行为。我也遇到过类似的问题,应该触发UIInterruption Monitor的伪抽头实际上是在提示出现之前执行的,这导致了无法处理提示。你可以创建一个小的期望值,等待你的应用程序加载(通过检查某个元素是否存在(或直到提示出现,然后执行虚拟点击。

最新更新