UI测试失败 - 未收到视图确实消失了2.0s内的通知错误

时间:2016-11-28 13:44:32

标签: swift xcode xctest xcode-ui-testing

我正在使用xcode 8编写我的测试套件UI自动化。但是,在尝试关闭警报时,我仍然遇到此问题。

我目前正在使用addUIInterruptionMonitor来解除我的提醒,但是当我使用app.tap()调用中断监视器时,我收到错误 UI测试失败 - 没有收到视图确实消失了2.0s内的通知错误

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

附件是我的应用启动代码

 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()
}

1 个答案:

答案 0 :(得分:0)

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

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

第三,如果您在监视器的处理程序上返回false,系统将点击该警报的“取消”按钮。在这种情况下,我更倾向于未通过测试,因为它是一个意外的系统警报。