简体   繁体   English

iOS XCUITest模拟指纹

[英]iOS XCUITest simulate fingerprint

I'm writing automated UI test using native tools. 我正在使用本机工具编写自动UI测试。 On one flow there is poped a fingerprint authentication. 在一个流上,弹出指纹认证。 How can I pass it, to move forward to next screen? 我如何通过它才能前进到下一个屏幕?

You cannot fake a fingerprint in a UITest. 您不能在UITest中伪造指纹。 To pass the authentication and test the part of you app that is shielded by the TouchID prompt you can run the test on a device that has not enabled TouchID. 要通过身份验证并测试应用程序被TouchID提示屏蔽的部分,您可以在未启用TouchID的设备上运行测试。 Or run it on a Simulator (without enabling TouchID). 或在模拟器上运行它(不启用TouchID)。

When TouchID is not enabled the OS asks you for the device's passcode. 如果未启用TouchID,则操作系统会要求您提供设备的密码。 You can enter the passcode and pass the authentication. 您可以输入密码并通过身份验证。 When running the test on a Simulator you can enter anything as passcode. 在模拟器上运行测试时,您可以输入任何内容作为密码。 It will always pass. 它会永远过去。

Here is an example test that passes the authentication by entering a passcode: 这是通过输入密码通过身份验证的示例测试:

func testExample() {
   let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
   let app = XCUIApplication()
   app.launch()

   // this causes the authentication prompt to be displayed
   app.buttons["Press Me!"].tap()

   let passcodeInput = springboard.secureTextFields["Passcode field"]
   passcodeInput.tap()
   passcodeInput.typeText("abc\r")

   // continue test
   ....
}

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

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