I'm trying to get past the User Notification system alert by following the flow presented in the follow post, which is the same flow mentioned in the UI testing cheat sheet and a few other posts on SO.
Xcode7 | Xcode UI Tests | How to handle location service alert?
I'm having a strange problem where I can't hit the OK button. Here is my code
addUIInterruptionMonitorWithDescription("User Notifications") { (alert) -> Bool in
let okButton = alert.buttons["OK"]
let dontAllowButton = alert.buttons["Don\u{2019}t Allow"]
print(okButton.frame)
print(dontAllowButton.frame)
okButton.tap() // Taps the dontAllowButton ??
return true
}
launchFinished() // wait for app to load and notification to show
app.tap()
The test successfully goes in the handler after I use app.tap()
and the buttons are found and exist, however it can't seem to actually tap the OK button! When I try to tap the OK button it taps the Dont Allow button, and when I try to tap the Dont Allow button, it doesn't tap anything.
The frames of the buttons don't match with what's on screen, either.
When I debug and look at the frames they are:
okButton = (431.5, 377.0, 44.0, 135.0)
dontAllowBtn = (431.5, 512.0, 44.0, 135.0)
Which seems to indicate they have the same X value, and one is on top of the other, which doesn't really make any sense.
Also, I've tried using XCUICoordinate
to create some coordinates near the buttons and tap the coordinates instead of the buttons, which is working fine for me in other places in the app, but no coordinate taps seem to register at all.
How do I get past this alert?
EDIT
I'm on Xcode 7.1.1 and the same problem is occurring with Location Services. It seems it has something to do with Landscape mode that is making it not work. When I create a fresh test app and run the above code it works fine in portrait mode. When I switch it to landscape mode it has the above behavior and does not work.
EDIT 2
I submitted a bug report to Apple.