Reputation: 83
In my unit tests there is a page that asks permisson for library usage. While my unit test running, this permisson dialog appears on screen and does not dissappear even if all of my unit tests finish. When UI Tests try to run, they can't cause of this dialog. Is there any way to run UI Tests before Unit Tests ?
Upvotes: 5
Views: 2961
Reputation: 2285
For me only this made it work:
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
//replace this "OK" with your button title
springboard.alerts.buttons["OK"].tap()
}
tapButtonThatTriggersThePermissionsDialog()
Upvotes: 0
Reputation: 322
If you are using XCode 9 you are able to interact with dialogs directly:
let systemAlerts = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts
if systemAlerts.buttons["Allow"].exists {
systemAlerts.buttons["Allow"].tap()
}
``
Upvotes: 14
Reputation: 27620
So your real problem is to get rid of the system dialog when running UITests. Running UITests before UnitTests won't change a thing, because then the system dialog would pop up during the UITest.
You can dismiss the dialog like this (in your UITest):
addUIInterruptionMonitor(withDescription: "“RemoteNotification” Would Like to Send You Notifications") { (alerts) -> Bool in
if(alerts.buttons["Allow"].exists){
alerts.buttons["Allow"].tap();
}
return true;
}
XCUIApplication().tap()
You have to change the description because the above code dismisses a system alert that asks for permission to send push notifications.
It is important that this code comes BEFORE your test triggers the system dialog. You can put it inside your test function right after you launch the app and before the test does anything else.
Upvotes: 1