简体   繁体   English

Xcode 7 UI Automation中的Dimiss触摸ID操作

[英]Dimiss Touch Id action in Xcode 7 UI Automation

我正在使用新的自动化框架在Xcode 7中编写UI测试用例,但没有获得方法名称来验证是否出现触摸提示,然后关闭显示在我的应用中的触摸ID提示。

I could not simulate finger touch but i was able to cancel the touch id prompt using addUIInterruptionMonitorWithDescription api available in the test framework 我无法模拟手指触摸,但是可以使用测试框架中可用的addUIInterruptionMonitorWithDescription api取消触摸ID提示

I used the below code to dismiss the dialog 我使用以下代码关闭了对话框

  addUIInterruptionMonitorWithDescription("Touch ID") { (alert) -> Bool in
                alert.buttons["Cancel"].tap()
                return true
            }
           app.tap()

You can dismiss a Touch ID prompt by invalidating authentication LAContext. 您可以通过使身份验证LAContext无效来消除Touch ID提示。 Dismissing TouchID prompt is introduced in iOS9:- 在iOS9中引入了关闭TouchID提示:-

func invalidateAuthenticationAlert(authContextObjext: LAContext){

    print("Dismiss current prompt")
    authContextObjext.invalidate()
}

Remember:- 记得:-

  • The context is invalidated automatically when it is (auto)released. 上下文在(自动)释放时自动失效。 This method allows invalidating it manually while it is still in scope. 此方法允许在范围内时手动使其无效。

  • Invalidation terminates any existing policy evaluation and the respective call will fail with LAErrorAppCancel. 无效将终止任何现有的策略评估,并且相应的调用将失败,并显示LAErrorAppCancel。 After the context has been invalidated, it can not be used for policy evaluation and an attempt to do so will fail with LAErrorInvalidContext. 上下文无效后,不能将其用于策略评估,并且尝试这样做会失败,并显示LAErrorInvalidContext。

  • Invalidating a context that has been already invalidated has no effect. 使已经无效的上下文无效无效。

In Xcode 9 you can access the Springboard to dismiss the TouchID prompt: 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
}

I was able to implement a solution for our project using this Biometrics testing repo here: 我可以在此处使用此生物特征测试测试仓库为我们的项目实施解决方案:

https://github.com/KaneCheshire/BiometricAutomationDemo https://github.com/KaneCheshire/BiometricAutomationDemo

After the event that kicks off the biometrics alert is completed, you will be able to handle that alert in a number of ways. 在启动生物识别警报的事件完成之后,您将可以通过多种方式处理该警报。 Using the Obj-C files provided in this repo (and implementing a bridging header) you can provide an invalid or valid biometric for the alert. 使用此存储库中提供的Obj-C文件(并实施桥接标头),您可以为警报提供无效或有效的生物识别信息。

Here is a cheat sheet for checking for the existence of an element and dismissing alerts: http://masilotti.com/ui-testing-cheat-sheet/ 这是一份备忘单,用于检查元素的存在并消除警报: http : //masilotti.com/ui-testing-cheat-sheet/

If you wish to tap "cancel" on the alert, you can do this a number of ways (as mentioned in the cheat sheet I posted) including using the Springboard API. 如果您希望在警报上点击“取消”,则可以使用多种方式(如我发布的备忘单中所述)执行此操作,包括使用Springboard API。

    func cancelBiometricAlert() {

    let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
    let biometricCancelButton = springboard.alerts.buttons["Cancel"].firstMatch
    if biometricCancelButton.exists {
        biometricCancelButton.tap()
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM