我正在使用Xcode7/iOS 9中引入的XCUIApplication,XCUIElement和XCUIElementQuery为我的应用程序编写UI测试用例.
我遇到了路障.测试用例中的一个屏幕需要iOS的位置服务.正如预期的那样,系统会提示用户允许使用名为" Allow “App name” to access your location while you use the app?with Allow&Don't Allowbuttons"的警报来使用位置服务.
问题是或许似乎由于警报由OS本身呈现,因此它不存在于Application的元素子树中.
我记录了以下内容:
print("XYZ:\(app.alerts.count)")//0
var existence = app.staticTexts["Allow “App Name” to access your location while you use the app?"].exists
print("XYZ:\(existence)")//false
existence = app.buttons["Allow"].exists
print("XYZ:\(existence)") //false
Run Code Online (Sandbox Code Playgroud)
甚至UI录制生成类似的代码:
XCUIApplication().alerts["Allow “App Name” to access your location while you use the app?"].collectionViews.buttons["Allow"].tap()
Run Code Online (Sandbox Code Playgroud)
我还没有找到任何可以让我解决这个问题的API.例如:
那我该怎么办呢?有没有办法配置测试目标,以便不需要位置服务授权.
我遇到了Xcode 7 UI测试的问题.
我的用户登录后,应用程序会显示两个警报,即请求位置警报和推送通知警报.这些通知一个接一个地显示.位置一出现在第一位.
我尝试自动解雇它们以开始我的测试.
为此,我添加了两个UIInterruptionMonitor,第一个用于Location Alert,第二个用于Notification Push Alert.
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
}
Run Code Online (Sandbox Code Playgroud)
但只触发Location 1,从不调用Push Notifications UIInterruptionMonitor的处理程序.
如果我在返回true 请求位置 UIInterruptionMonitor因为这等后接受的答案指定.两个处理程序都被调用,但两个UIInterruptionMonitor中的alert参数都链接到请求位置警报视图,因此永远找不到"确定"按钮.
如何解除这两个连续的警报视图?