It's been almost two years since iOS devices started supporting Face ID. This feature is incredibly handy to users, and expected in major apps, yet the integration can be tricky and I've seen some corner cases handled badly. Appium is able to support testing in-app authentication with Face ID on iOS simulators, since the simulator app has this capability built into it.
There are only three limited controls provided by the simulator, and Appium provides the same three actions:
- matching face
- non-matching face
enroll sets up the device for Face ID. This is equivalent to scanning your face during device setup and enabling the feature. You can toggle this on and off, to make sure that your app works for users who have opted out of the technology.
The command can be sent via one of Appium's custom mobile: script commands.
This command should be called once the test session has started. Don't worry about calling it twice, setting the same value that's been set before doesn't cause an error. The simulator will remember the value it's been set to though, so don't bet on it being in a certain state at the beginning of a test run.
Once enabled, we need to perform whatever action in the app results in prompting for a face to unlock it. Once prompted, we can then either present the device with the correct simulated face, or an incorrect face.
Replacing faceId with touchId will perform the same function but for the older fingerprint ID feature.
I found a useful demo app on github which has a simple Face ID login button to test this on. Below is a complete test. The full code file and a compiled demo app can be found in our example code repository: