Xcode 9
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") let allowBtn = springboard.buttons["Allow"] if allowBtn.exists { allowBtn.tap() }
Xcode 8.3.3
_ = addUIInterruptionMonitor(withDescription: "Location Dialog") { (alert) -> Bool in alert.buttons["Allow"].tap() return true } app.buttons["Request Location"].tap() app.tap()
Note that this is slightly different, as the method name is now addUIInterruptionMonitor and takes withDescription as an argument
Xcode 7.1
Xcode 7.1 has finally fixed the system alert issue. There are, however, two small errors.
First, you need to set up a "user interface interrupt handler" before presenting a warning. This is our way to tell the framework how to handle an alert when it appears.
Secondly, after giving a warning you should interact with the interface. A simple click on the application works just fine, but it is necessary.
addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in alert.buttons["Allow"].tap() return true } app.buttons["Request Location"].tap() app.tap()
The "location dialog" is just a line that helps the developer determine which handler was accessed; it does not belong to the type of alert.
Xcode 7.0
The following will reject the only "system warning" in Xcode 7 Beta 6:
let app = XCUIApplication() app.launch() // trigger location permission dialog app.alerts.element.collectionViews.buttons["Allow"].tap()
Beta 6 introduced many fixes for UI Testing, and I believe this was one of them.
Also note that I'm calling -element directly on -alerts . Calling -element for XCUIElementQuery forces the platform to select the "one and only" corresponding element on the screen. This works great for alerts when you can only see one image at a time. However, if you try this for a label and you have two labels, the framework will throw an exception.
Joe Masilotti Aug 26 '15 at 1:25
source share