Biometric security systems can replace the traditional method of entering passwords or PINs with a swipe of a finger so that the phone can be unlocked and used. We know that the 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 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 the 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. You can use the following command to enroll:
driver.executeScript(“mobile:enrollBiometric”, ImmutableMap.of(“isEnabled”, true));
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 (enrolled), 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. Following are the commands to matching face and non-matching face:
// checking matching face
driver.executeScript(“mobile:sendBiometricMatch”, ImmutableMap.of(“type”, “faceId”, “match”, true));
// checking non-matching face
driver.executeScript(“mobile:sendBiometricMatch”, ImmutableMap.of(“type”, “faceId”, “match”, false));
Note: Replacing faceId with touchId will perform the same function but for the fingerprint ID feature.
Try to use the above logic to automate Face ID in iOS Simulator.
Reference: Appium Pro
make it perfect!
Leave a Reply