Example - FaceId authentication in iPhone Simulator using Appium

Some important points

  1. FaceId is applicable to iPhone X onwards models
  2. You need to enroll the FaceID
  3. Then You can send matching and Non matching FaceID simulation
  4. This is generally used in Biometrics applications
  5. This is supported in only simulators and not in Real phones

Below code demonstrates how you can simulate the face id in iPhone Simulator.
package org.softpost.ios.simulator;
import com.google.common.collect.ImmutableMap;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.URL;
import java.util.concurrent.TimeUnit;

public class FaceIdTest {
    AppiumDriver driver;
    @Test
    public void testFaceId() throws Exception{
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("platformName", "iOS");
        caps.setCapability("platformVersion", "13.0");
        caps.setCapability("deviceName", "iPhone X");
        caps.setCapability("AutomationName" , "XCUITest");

        caps.setCapability("wdaLocalPort", 8100);

        caps.setCapability("bundleId", "com.apple.MobileAddressBook");

        try {
            driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

            driver.executeScript("mobile:enrollBiometric", ImmutableMap.of("isEnabled", true));

            //Perform passing faceid authentication
            driver.executeScript("mobile:sendBiometricMatch", ImmutableMap.of("type", "faceId", "match", true));

            //Perform failing faceid authentication
            driver.executeScript("mobile:sendBiometricMatch", ImmutableMap.of("type", "faceId", "match", false));
            Thread.sleep(2000);
        }catch (Exception ex){
            ex.printStackTrace();
        }finally {
            driver.quit();
        }
    }
}

Example - TouchID authentication in iPhone Simulator using Appium

package org.softpost.ios.simulator;
import com.google.common.collect.ImmutableMap;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.URL;
import java.util.concurrent.TimeUnit;

public class TouchIdTest {
    IOSDriver driver;
    @Test
    public void test() throws Exception{
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("platformName", "iOS");
        caps.setCapability("platformVersion", "13.0");
        caps.setCapability("deviceName", "iPhone 7");
        caps.setCapability("AutomationName" , "XCUITest");
        caps.setCapability("allowTouchIdEnroll" , true);


        caps.setCapability("wdaLocalPort", 8100);
       // caps.setCapability("app", "/Users/admin/iosapps/softpost.app");


        caps.setCapability("bundleId", "com.apple.MobileAddressBook");

        try {
            driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

            //passing touchid
            driver.performTouchID(true);

            //failing touchid
            driver.performTouchID(false);

            Thread.sleep(2000);
        }catch (Exception ex){
            ex.printStackTrace();
        }finally {
            driver.quit();
        }

    }

}

Youtube | Facebook | Twitter | Website Home | Online Grocery Shopping Brisbane