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?
Asked
Active
Viewed 2,904 times
6
-
Here is the link. Explore it and you will get your answers. https://appium.readthedocs.io/en/stable/en/commands/device/simulator/toggle-touch-id-enrollment/ – Shivam Nov 30 '18 at 11:46
-
1Thanks a lot. Thats what i was looking as well but for XCUITest. I had a look but couldn't found anything. Any direction or help? – sjgmamer Nov 30 '18 at 13:00
2 Answers
7
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
.

Axel Guilmin
- 11,454
- 9
- 54
- 64
-
1According to https://github.com/facebook/WebDriverAgent/issues/26, it should be possible to simulate a match with `notify_post("com.apple.BiometricKit_Sim.fingerTouch.match")` and a non-match with `notify_post("com.apple.BiometricKit_Sim.fingerTouch.nomatch")`. – Mats Dec 04 '18 at 14:17
-
2
-
Wow. Thanks a lot Axel for direction. This post looks really impressive. – sjgmamer Dec 04 '18 at 14:26
-
-
1Found it here: https://medium.com/kinandcartacreated/so-you-want-to-automate-ios-biometrics-81bd015f5d38 – reutsey Sep 04 '20 at 16:28
1
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")

Abhishek Bedi
- 5,205
- 2
- 36
- 62