【问题标题】:Dimiss Touch Id action in Xcode 7 UI Automation在 Xcode 7 UI 自动化中关闭 Touch Id 操作
【发布时间】:2016-03-16 07:31:19
【问题描述】:

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

【问题讨论】:

    标签: ios xcode ios-ui-automation


    【解决方案1】:

    我无法模拟手指触摸,但我能够使用测试框架中提供的 addUIInterruptionMonitorWithDescription api 取消触摸 id 提示

    我使用下面的代码来关闭对话框

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

    【讨论】:

    • 似乎监视器在 Xcode 9 中不再工作了。未调用完成块
    【解决方案2】:

    您可以通过使身份验证 LAContext 无效来关闭 Touch ID 提示。 iOS9 中引入了关闭 TouchID 提示:-

    func invalidateAuthenticationAlert(authContextObjext: LAContext){
    
        print("Dismiss current prompt")
        authContextObjext.invalidate()
    }
    

    记住:-

    • 上下文在(自动)释放时会自动失效。此方法允许在其仍在范围内时手动使其无效。

    • 失效会终止任何现有的策略评估,并且相应的调用将失败并显示 LAErrorAppCancel。上下文失效后,它不能用于策略评估,并且尝试这样做会失败并显示 LAErrorInvalidContext。

    • 使已经无效的上下文无效。

    【讨论】:

    • 使用代码很容易消除警报,但我想监控 UI 测试中 UI 上出现的系统触摸 id 警报
    • 我也想做同样的事情。似乎无法通过代码复制模拟器的 TouchID Enrolled 和 Simulated Finger Touch 功能。如果您找到答案,可以发帖吗?如果没有,您可能需要考虑向 Apple 提交功能请求。
    【解决方案3】:

    在 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
    }
    

    【讨论】:

      【解决方案4】:

      我能够在此处使用此生物识别测试存储库为我们的项目实施解决方案:

      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()
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2015-12-27
        • 2011-01-07
        • 2016-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-05
        • 2017-01-28
        • 2012-11-11
        相关资源
        最近更新 更多