UI 测试失败 - 没有收到视图确实在 2.0 秒内消失的通知错误 [英] UI testing failure - did not receive view did disappear notifications within 2.0s error

查看:33
本文介绍了UI 测试失败 - 没有收到视图确实在 2.0 秒内消失的通知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xcode 8 编写我的测试套件 UI 自动化.但是我在尝试关闭警报时不断遇到这个问题.

I am writing my test suite UI automation with xcode 8. However I keep occurring into this problem while trying to dismiss alerts.

我目前正在使用 addUIInterruptionMonitor 来解除警报,但是当我使用 app.tap() 调用中断监视器以触发时,我收到错误 UI 测试失败 - 未收到视图确实在 2.0 秒内消失的通知错误

I am currently using the addUIInterruptionMonitor in order to dismiss my alerts, however when I call the interruption monitor to fire using app.tap() I get the error UI testing failure - did not receive view did disappear notifications within 2.0s error

为什么会发生这种情况,我该如何防止这种情况发生?

Why is this happening and how can I prevent this from happening?

附件是我的应用程序启动代码

Attached is my start up code for the app

 override func setUp() {
    super.setUp()
    XCUIApplication().terminate()
    continueAfterFailure = false
    app.launch()

    addUIInterruptionMonitorWithDescription("Enable Notifications") { (alert) -> Bool in
       let button =  alert.buttons["OK"]
        if button.exists{
            button.tap()
            return true
        }
        return false
    }
    app.buttons["Enable notifications"].tap()

    app.tap()

    XCTAssert(app.tabBars.buttons["Settings"].exists)
    app.tabBars.buttons["Settings"].tap()
}

推荐答案

首先,在 app.launch() 之前添加监视器,你就不需要 app.tap()

First, add the monitor before app.launch() and you'll not need app.tap()

其次,app.buttons["Enable notification"].tap() 是警报出现的触发器,如果​​没有,请删除该行.

Second, is the app.buttons["Enable notifications"].tap() the trigger for the alert to appear, if not, remove that line.

第三,如果您在监视器的处理程序上返回 false,系统将点击该警报的取消"按钮.在这种情况下,我更喜欢测试失败,因为这是一个意外的系统警报.

Third, if you return false on the monitor's handler, the system will tap the "cancel" button for that alert. I prefere to fail the test in this case since it's an unexpected system alert.

这篇关于UI 测试失败 - 没有收到视图确实在 2.0 秒内消失的通知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆