2

I have a ViewController that will request access to location services on init via

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
    [_locationManager requestWhenInUseAuthorization];
}

This triggers the "Allow app to access your location while you use the app?"-alert.

I use [self addUIInterruptionMonitorWithDescription:handler:] to react to this. I am encountering the following problem: after dismissing the request-dialog, the ui-test does not continue. The alert is dismissed, but Xcode waits for the app to become idle, but it looks like the app is idle:

t =    67.35s             Wait for app to idle

The test fails, because the app is stuck here. If i tap into the simulator, Xcode logs.

t =    72.27s         Synthesize event

and continues the test.

Is there a reason, why Xcode tries to wait for the app? A workaround seems to be to tell Xcode that the UI changed or an event happened. Is there a way to trigger this?

Tobias
  • 1,220
  • 17
  • 35

1 Answers1

10

After presenting the alert you must interact with the interface. This is a known bug with Xcode 7.2. Simply tapping the app works just fine, but is required.

addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
    alert.buttons["Allow"].tap()
    return true
}

app.buttons["Find Games Nearby?"].tap()
app.tap() // need to interact with the app for the handler to fire
XCTAssert(app.staticTexts["Authorized"].exists)

See my blog post for more information.

Joe Masilotti
  • 16,815
  • 6
  • 77
  • 87
  • Thanks for the help. In fact, i knew your blog post before and tried to use this, but after the interruption monitor, tapping does not work, because Xcode thinks, the app is not idle. The test will fail with ´UI Testing Failure - App failed to quiesce within 30s´ – Tobias Jan 04 '16 at 12:06
  • Interesting. It sounds like there might be something else going on in your app that is causing the framework to think it is not responsive. Is anything else happening in that method, maybe on the main thread? – Joe Masilotti Jan 04 '16 at 14:28
  • I ask for permission in the viewControllers' init. While waiting, a MKMapSnapshot is done (on a given Coordinate, not the users location) and added to a UITableView. The TableView is then reloaded. The Refreshcontrol is stoppend. Then the user/test taps onto "allow" and the focus returns to the ViewController. – Tobias Jan 04 '16 at 14:44
  • Since the user-location is not a vital feature, i ended up, removing the dialog while running UI-Tests using this method: http://stackoverflow.com/a/33038143/1315242 – Tobias Jan 05 '16 at 06:41