Search code examples
iosxcuitest

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?


Solution

  • 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.