问题
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