5

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.

User Notification Alert Buttons

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.

Community
  • 1
  • 1
Alex
  • 3,861
  • 5
  • 28
  • 44
  • What happens if you present a Location Services Authorization dialog but run the same code? Can you tap the "Allow" button? – Joe Masilotti Dec 10 '15 at 14:22
  • @JoeMasilotti I tried the location services and it is the same story exactly, I'm on Xcode 7.1.1 – Alex Dec 10 '15 at 15:02
  • @JoeMasilotti I tried making a fresh test app and running the above code and it works fine in portrait mode, but in landscape mode I'm getting the same button frames and inability to click OK – Alex Dec 10 '15 at 15:32
  • Interesting. Sounds like a bug with UI Testing? I suggest filing a radar (if you haven't already) with that sample code showing it working in portrait but not landscape. – Joe Masilotti Dec 10 '15 at 16:03
  • I also wouldn't recommend using app.tap() to kick in the handler, since it will tap an existing element on the screen (which may be a button). I've had issues with this previously, which i solved by just using `app.swipeUp()` – Andriko13 Jun 07 '17 at 20:45

0 Answers0