简体   繁体   中英

Is it possible to automate touch ID or face ID using xcuitest in simulator?

Is there a way to automate face ID or Touch ID using xcuitest framework in simulator. Manually I can perform enrolling face/touch id and perform matching or non-matching scenarios. However I would like to know if it can be automated?

Given this post by Kane Cheshire it is possible to automate touch ID and face ID for unit testing by sending a Darwin notification like so :

+ (void)enrolled {
  int token;
  notify_register_check("com.apple.BiometricKit.enrollmentChanged", &token);
  notify_set_state(token, 1);
  notify_post("com.apple.BiometricKit.enrollmentChanged");
}

Only in Objective-C though, so you may need to use a bridging header.

Import the files Biometrics.m and Biometrics.h from his demo on Gitub and you will be able to call Biometrics.enrolled() from your XCTestCase .

Alternatively, if the Touch/FaceId is blocking your XCUITesting, I suggest, you put a simple check like the below to disable the Touch/faceId

guard CommandLine.isRunningUITests else {
    return true
}
extension CommandLine {
    static var isRunningUITests:Bool {
        return CommandLine.arguments.contains("--uitesting")
    }
}

You can easily pass LaunchArguments like below

XCUIApplication().launchArguments.append("--uitesting")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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