问题
I am trying to record a UI test case and run it back, but I am running into this error. Basically, in my application when I land on the home screen, the user is asked to allow use of notification and location. After I record these events and try to segue to another VC, it records normally like so.
[app.alerts[@"\u201cSampleApp\u201d Would Like to Send You Notifications"].collectionViews.buttons[@"Don\u2019t Allow"] tap];
[app.alerts[@"Allow \u201cSampleApp\u201d to access your location while you use the app?"].collectionViews.buttons[@"Allow"] tap];
//segue to VC2
But when I play it back, it fails with the error in the title.
Did not receive view did disappear notification within 2.0s
I suspect that by the time the alerts are cleared, the segue button is already tapped and while it expects the home VC to disappear, it does not. Is this understanding right?. If yes, how can I delay the expectation, if no, please help.
回答1:
System level alerts should be handled by addUIInterruptionMonitorWithDescription
API here is the documentation from apple Link and sample code in swift below:
addUIInterruptionMonitorWithDescription("First Dialog") { (alert) -> Bool in
alert.buttons["Allow"].tap()
return true
}
XCUIApplication().tap()
来源:https://stackoverflow.com/questions/39391255/ui-testing-failure-did-not-receive-view-did-disappear-notification-within-2-0s