“UI测试失败:未收到视图确实在2.0秒内消失通知”错误

时间:2016-09-08 12:41:51

标签: ios objective-c iphone xcode xcode-ui-testing

我正在尝试记录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.0秒内消失通知

我怀疑在清除警报时,已经点击了segue按钮,虽然它期望家庭VC消失,但它没有。这种理解是对的吗?如果是,我怎么能延迟期望,如果没有,请帮助。

1 个答案:

答案 0 :(得分:3)

系统级警报应由addUIInterruptionMonitorWithDescription API处理,这里是来自apple Link的文档,以及下面swift中的示例代码:

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

XCUIApplication().tap()