我正在使用新的Xcode 7 UI测试功能编写UI测试用例.在我的应用程序的某些时刻,我要求用户允许相机访问和推送通知.因此会出现两个iOS弹出窗口:"MyApp Would Like to Access the Camera"弹出窗口和"MyApp Would Like to Send You Notifications"弹出窗口.我希望我的测试可以解雇两个弹出窗口.
UI录制为我生成了以下代码:
[app.alerts[@"cameraAccessTitle"].collectionViews.buttons[@"OK"] tap];
Run Code Online (Sandbox Code Playgroud)
但是,[app.alerts[@"cameraAccessTitle"] exists]解析为false,上面的代码生成错误:Assertion Failure: UI Testing Failure - Failure getting refresh snapshot Error Domain=XCTestManagerErrorDomain Code=13 "Error copying attributes -25202".
那么在测试中解除一堆系统警报的最佳方法是什么?系统弹出窗口会中断我的应用程序流并立即使我的正常UI测试用例失败.事实上,任何有关如何绕过系统警报以便我可以恢复测试通常流程的建议都表示赞赏.
这个问题可能与这个SO帖子有关,也没有答案:Xcode7 | Xcode UI测试| 如何处理位置服务警报?
提前致谢.
以下测试在iOS 11上运行正常.它解除了警告,要求使用位置服务的权限,然后放大地图.在iOS 10或9上,它没有做到这一点,测试仍然成功
func testExample() {
let app = XCUIApplication()
var handled = false
var appeared = false
let token = addUIInterruptionMonitor(withDescription: "Location") { (alert) -> Bool in
appeared = true
let allow = alert.buttons["Allow"]
if allow.exists {
allow.tap()
handled = true
return true
}
return false
}
// Interruption won't happen without some kind of action.
app.tap()
removeUIInterruptionMonitor(token)
XCTAssertTrue(appeared && handled)
}
Run Code Online (Sandbox Code Playgroud)
有没有人知道为什么和/或解决方法?
这是一个可以重现问题的项目:https://github.com/TitouanVanBelle/Map
更新
Xcode 9.3 Beta的更新日志显示如下
XCTest UI interruption monitors now work correctly on …Run Code Online (Sandbox Code Playgroud)