我遇到 Xcode 7 UI 测试问题。
该应用在我的用户登录后显示两个警报,请求位置 警报和推送通知 警报。这些通知一个接一个地显示。位置第一个出现。
我尝试自动关闭它们以开始我的测试。
为此,我添加了两个 UIInterruptionMonitor,第一个用于位置警报,第二个用于通知推送警报。
addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
/* Dismiss Location Dialog */
if alert.collectionViews.buttons["Allow"].exists {
alert.collectionViews.buttons["Allow"].tap()
return true
}
return false
}
addUIInterruptionMonitorWithDescription("Push Dialog") { (alert) -> Bool in
/* Dismiss Push Dialog */
if alert.collectionViews.buttons["OK"].exists {
alert.collectionViews.buttons["OK"].tap()
return true
}
return false
}
但只有 Location 被触发,Push Notifications 的处理程序 UIInterruptionMonitor 永远不会被调用。
如果我在 Request Location UIInterruptionMonitor 中返回 true 作为 this other post accepted answer指定。两个处理程序都被调用,但是 UIInterruptionMonitor 中的 alert 参数链接到 Request Location 警报 View ,因此永远找不到“确定”按钮。
如何关闭这两个连续的警报 View ?
最佳答案
虽然不理想,但我发现如果您只是等到一个授权对话框完成后再在应用中显示另一个授权对话框,UI 测试可以连续接收多个请求。
if CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse || CLLocationManager.authorizationStatus() == .AuthorizedAlways {
self.locationManager.requestLocation()
} else {
self.contactStore.requestAccessForEntityType(.Contacts) { _ in
self.locationManager.requestWhenInUseAuthorization()
}
}
我实际上是在我的代码中的不同位置请求访问联系人,但它可以很好地处理多个同时请求。
然后在我的测试中:
addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
let button = alert.buttons["Allow"]
if button.exists {
button.tap()
return true
}
return false
}
addUIInterruptionMonitorWithDescription("Contacts Dialog") { (alert) -> Bool in
let button = alert.buttons["OK"]
if button.exists {
button.tap()
return true
}
return false
}
app.buttons["Location"].tap()
app.tap() // need to interact with the app for the handler to fire
app.tap() // need to interact with the app for the handler to fire
关于ios - Xcode 7 用户界面测试 : Dismiss Push and Location alerts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33875301/