【发布时间】:2016-03-16 07:31:19
【问题描述】:
我正在使用新的自动化框架在 Xcode 7 中编写 UI 测试用例,但我没有获得方法名称来验证是否出现触摸提示,然后关闭我的应用程序中显示的触摸 id 提示。
【问题讨论】:
标签: ios xcode ios-ui-automation
我正在使用新的自动化框架在 Xcode 7 中编写 UI 测试用例,但我没有获得方法名称来验证是否出现触摸提示,然后关闭我的应用程序中显示的触摸 id 提示。
【问题讨论】:
标签: ios xcode ios-ui-automation
我无法模拟手指触摸,但我能够使用测试框架中提供的 addUIInterruptionMonitorWithDescription api 取消触摸 id 提示
我使用下面的代码来关闭对话框
addUIInterruptionMonitorWithDescription("Touch ID") { (alert) -> Bool in
alert.buttons["Cancel"].tap()
return true
}
app.tap()
【讨论】:
您可以通过使身份验证 LAContext 无效来关闭 Touch ID 提示。 iOS9 中引入了关闭 TouchID 提示:-
func invalidateAuthenticationAlert(authContextObjext: LAContext){
print("Dismiss current prompt")
authContextObjext.invalidate()
}
记住:-
上下文在(自动)释放时会自动失效。此方法允许在其仍在范围内时手动使其无效。
失效会终止任何现有的策略评估,并且相应的调用将失败并显示 LAErrorAppCancel。上下文失效后,它不能用于策略评估,并且尝试这样做会失败并显示 LAErrorInvalidContext。
使已经无效的上下文无效。
【讨论】:
在 Xcode 9 中,您可以访问 Springboard 以关闭 TouchID 提示:
func testExample() {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let app = XCUIApplication()
app.launch()
// this causes the TouchID prompt to be displayed
app.buttons["Press Me!"].tap()
if springboard.alerts.buttons["Cancel"].waitForExistence(timeout: 10) {
springboard.alerts.buttons["Cancel"].tap()
}
// continue test
}
【讨论】:
我能够在此处使用此生物识别测试存储库为我们的项目实施解决方案:
https://github.com/KaneCheshire/BiometricAutomationDemo
启动生物识别警报的事件完成后,您将能够以多种方式处理该警报。使用此 repo 中提供的 Obj-C 文件(并实现桥接头),您可以为警报提供无效或有效的生物特征。
这是检查元素是否存在并消除警报的备忘单:http://masilotti.com/ui-testing-cheat-sheet/
如果您希望点击警报上的“取消”,您可以通过多种方式(如我发布的备忘单中所述)执行此操作,包括使用 Springboard API。
func cancelBiometricAlert() {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let biometricCancelButton = springboard.alerts.buttons["Cancel"].firstMatch
if biometricCancelButton.exists {
biometricCancelButton.tap()
}
}
【讨论】: