Join the webinar on 'Open source GenAI tools for Test Automation' on May 28th or May 30th.
Testing iOS Face ID with Appium

Testing iOS Face ID with Appium

July 31, 2019
 Jonathan Lipps Jonathan Lipps
Jonathan Lipps

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:

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

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

driver.executeScript("mobile:sendBiometricMatch", ImmutableMap.of("type", "faceId", "match", true));
// or
driver.executeScript("mobile:sendBiometricMatch", ImmutableMap.of("type", "faceId", "match", false));

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:

public class Edition080_iOS_FaceId {
    // App provided by
    File classpathRoot = new File(System.getProperty("user.dir"));
    File appDir = new File(classpathRoot, "../apps/");
    String app = new File(appDir.getCanonicalPath(), "").getAbsolutePath();
    private IOSDriver driver;

    public Edition080_iOS_FaceId() throws IOException {

    public void setUp() throws IOException {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("platformName", "iOS");
        caps.setCapability("platformVersion", "12.4");
        caps.setCapability("deviceName", "iPhone Xs");
        caps.setCapability("automationName", "XCUITest");

        caps.setCapability("app", app);

        driver = new IOSDriver(new URL("http://localhost:4723/wd/hub"), caps);

    public void tearDown() {
        try {
        } catch (Exception ign) {}

    public void testIOSFaceId() {
        driver.executeScript("mobile:enrollBiometric", ImmutableMap.of("isEnabled", true));
        WebElement loginButton = driver.findElementByAccessibilityId("Log In");;


        driver.executeScript("mobile:sendBiometricMatch", ImmutableMap.of("type", "faceId", "match", true));

        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.presenceOfElementLocated("Log Out")));

        WebElement logoutButton = driver.findElementByAccessibilityId("Log Out");;

        wait.until(ExpectedConditions.presenceOfElementLocated("Log In")));

        loginButton = driver.findElementByAccessibilityId("Log In");;

        driver.executeScript("mobile:sendBiometricMatch", ImmutableMap.of("type", "faceId", "match", false));


Testing iOS Face ID with Appium

4 Parts


Perfect Digital Experiences with Data Science Capabilities

Utilize HeadSpin's advanced capabilities to proactively improve performance and launch apps with confidence
popup image