UI testing failure - did not receive view did disappear notifications within 2.0s error

断了今生、忘了曾经 提交于 2020-01-15 05:09:10

问题


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

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

回答1:


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

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

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.



来源:https://stackoverflow.com/questions/40845784/ui-testing-failure-did-not-receive-view-did-disappear-notifications-within-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!