Inject biometric data with Appium
On an mobile device, you can inject a passing or failing fingerprint or face ID, depending on the device model, to test different authentication scenarios.
To learn more about biometric injection, including requirements and limitations, see Biometric injection overview.
To activate biometric injection from an Appium script, edit your Appium script as follows:
-
Add the code relevant to install the application:
-
If you install the application as part of the driver creation, add the following capability setting:
Copycapabilities.setCapability("perfecto:sensorInstrument", true);
-
If you install the application with the Perfecto extension command
mobile:application:install
, supply thesensorInstrument
parameter with a value ofsensor
.CopyMap<String, Object> params = new HashMap<>(); // use either the "identifier" or "name" parameter to identify the app
params.put("sensorInstrument", "sensor"); // <<additional parameters to identify the application to install>> ooo
driver.executeScript("mobile:application:install", params);
-
-
Activate fingerprint injection:
-
Identify the location in the script where the application should prompt the user to identify through the sensor reader.
-
Add the
mobile:sensorAuthentication:set
command to inject the fingerprint, as follows.CopyMap<String, Object> params = new HashMap<>();
// use either the "identifier" or "name" parameter to identify the app
params.put("identifier", <application package identifier>);
params.put("resultAuth", "fail"); // may be either "fail" or "success"
params.put("errorType", "lockOut"); // may be authFailed, userCancel, userFallback, systemCancel, or lockout
driver.executeScript("mobile:sensorAuthentication:set", params);
If the automation script simulates a failure result (meaning the
resultAuth
parameter is set tofail
), theerrorType
parameter indicates more information on why the authentication failed. This allows the script to activate different failure scenarios. The error types supported include:-
authFailed: Indicates that the biometric identification was not recognized and therefore not authenticated.
-
userFallback: Indicates that the user selected an option to provide a different authentication method, for example using a password.
-
userCancel: Indicates that the user selected an option to cancel the authentication.
-
systemCancel: Indicates that the system canceled the authentication.
-
lockout: Indicates that this is a multiple-failure scenario and the user account should be locked.
-