0

I am am writing my XCUITests for my app, and currently struggling in finding the best solutions to dismiss my apps alerts. I have two sets of alerts, one is a notifications alert which pops up at the beginning of a fresh install, the second is a location alert when I navigate to the nearby tab on my app after a fresh install. I have tried using

let alert = app.alerts["\u{201c}VoucherCodes\u{201d} Would Like to Send You Notifcations"].collectionViews.buttons["OK"]
    if alert.exists{
        alert.tap()
    } 

but no success, I have also tried using a systemAlertMonitorTokenin my my setUp()

   systemAlertMonitorToken = addUIInterruptionMonitorWithDescription(systemAlertHandlerDescription) { (alert) -> Bool in
        if alert.buttons.matchingIdentifier("OK").count > 0 {
            alert.buttons["OK"].tap()
            return true
        } else {
            return false
        }
    }

Does anyone have any suggestions or point out where I am going wrong so I can fix this, thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Billy Boyo
  • 819
  • 2
  • 12
  • 22
  • Possible duplicate of [Xcode 7 UI Testing: how to dismiss a series of system alerts in code](http://stackoverflow.com/questions/32148965/xcode-7-ui-testing-how-to-dismiss-a-series-of-system-alerts-in-code) – Joe Masilotti Sep 14 '16 at 10:26
  • This question seems to be asking how to dismiss multiple alerts, or an alert that may or may not be presented depending on previous settings, not just how to dismiss an alert. – Alex Sep 21 '16 at 14:06

1 Answers1

0

You might find these two questions and their answers to be illuminating:

Xcode 7 UI Testing: Dismiss Push and Location alerts

Xcode 7 UI Testing: how to dismiss a series of system alerts in code

Community
  • 1
  • 1
Aaron Sofaer
  • 706
  • 4
  • 19