中断后等待应用程序空闲

Tob*_*ias 2 xcode7 xcode-ui-testing

我有一个ViewController,它将在init上请求访问位置服务

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
    [_locationManager requestWhenInUseAuthorization];
}
Run Code Online (Sandbox Code Playgroud)

这会触发"允许应用在您使用应用时访问您的位置?" - 提醒.

[self addUIInterruptionMonitorWithDescription:handler:]用来对此做出反应.我遇到以下问题:在解除请求对话框后,ui-test不会继续.该警报被驳回,但Xcode中等待应用程序成为空闲,但它看起来像应用程序空闲的:

t =    67.35s             Wait for app to idle
Run Code Online (Sandbox Code Playgroud)

测试失败,因为应用程序卡在这里.如果我点击模拟器,Xcode记录.

t =    72.27s         Synthesize event
Run Code Online (Sandbox Code Playgroud)

并继续测试.

有没有理由,为什么Xcode试图等待应用程序?解决方法似乎是告诉Xcode UI已更改或事件发生.有没有办法触发这个?

Joe*_*tti 10

在显示警报后,您必须与界面进行交互.这是Xcode 7.2的一个已知错误.只需点击应用程序就可以正常工作,但这是必需的.

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)
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅我的博文.