"UI Testing Failure: Did not receive view did disappear notification within 2.0s" 错误

"UI Testing Failure: Did not receive view did disappear notification within 2.0s" error

我正在尝试记录一个 UI 测试用例并 运行 它回来,但我 运行 遇到了这个错误。基本上,在我的应用程序中,当我登陆主屏幕时,系统会要求用户允许使用通知和位置。在我记录这些事件并尝试转到另一个 VC 之后,它通常会这样记录。

[app.alerts[@"\u201cSampleApp\u201d Would Like to Send You Notifications"].collectionViews.buttons[@"Don\u2019t Allow"] tap];
[app.alerts[@"Allow \u201cSampleApp\u201d to access your location while you use the app?"].collectionViews.buttons[@"Allow"] tap];
//segue to VC2

但是当我播放它时,它失败了,标题中有错误。

2.0s内未收到查看消失通知

我怀疑当警报被清除时,segue 按钮已经被点击,虽然它希望主页 VC 消失,但它没有。这个理解对吗?。如果是,我该如何延迟期望,如果不是,请帮助。

系统级警报应由 addUIInterruptionMonitorWithDescription 处理 API 以下是 apple Link 的文档和下面 swift 中的示例代码:

addUIInterruptionMonitorWithDescription("First Dialog") { (alert) -> Bool in
alert.buttons["Allow"].tap()
return true
}

XCUIApplication().tap()