swift - UI 测试失败 - 没有收到 view did disappeared notifications within 2.0s 错误

标签 swift xcode xctest xcode-ui-testing

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

我目前正在使用 addUIInterruptionMonitor 来关闭我的警报,但是当我使用 app.tap() 调用中断监视器触发时,我收到错误 < strong>UI 测试失败 - 没有收到 view did disappeared notifications within 2.0s error

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

附件是我的应用启动代码

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

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

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

关于swift - UI 测试失败 - 没有收到 view did disappeared notifications within 2.0s 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40845784/

相关文章:

swift - 如何在快速测试中使用用户定义的配置变量作为 @testable import 中的模块名称?

ios - 如何在值为动态时增加数组的索引(Swift)

arrays - 如何在 Swift 2 中使结构成为可订阅的?

快速比较 switch 语句中的元组与 or

ios - 在目标build设置中找不到 Apple LLVM 8.0 - 自定义编译器标志

ios - 越狱后,iOS 应用程序会以 root 权限运行吗?

ios - 如何在应用程序中访问 Xcode 的 "Supporting Files"组中的文件?

ios - rootViewController 呈现 View 时进行单元测试?

ios - 在 Xcode 5.1 中使用 XCTAssertEqual 比较 CGPoint 时出错

ios - UIViewController 如何设法在 Swift 中拥有默认的无参数初始化程序?