Supported only on devices that allow TouchID
Simulates different authentication responses on applications that request a user fingerprint authentication.
This method allows setting the desired response type for later authentication requests.
By doing so, you can verify the response of your application in different authentication scenarios.
In a nutshell, this is a mock authentication command.
- Reply: The reply type to mock (possible values can be found in the link below- in the first note).
- Delay: Delay after authentication request dialog is open ( must be an integer bigger than zero ).
Prior to instrumentation, you need to configure either of the following app properties :
- Set the android.instrument.fingerprint as true if your app implements a standard fingerprint authentication dialog.
- Set the android.instrument.fingerprint.secure as true if your fingerprint implementation involves security authentications for the responses received from the user.
After instrumenting the Application with mock authentication property the application may not support manual authentication (can't authenticate with a real fingerprint).
In order to use setMockAuthenticationReply command on your application, your application needs to be Instrumented, you can achieve this by:
- Import/re-instrument your app via Application Manager or use install command with instrument=true.
- For iOS applications, you can also use manual instrumentation to instrument the app manually: SeeTestAutomation - Manually Instrumenting iOS Applications
Until 20.5, the supported usage for this command was to call it after the authentication request dialog appears.
20.5 and later, it is recommended to use this command before the application. i.e., the command sets the desired reply for future authentication requests.
The following examples are demonstrated in the BiometricAuthentication sample application. Note that some of the dialogs can change, depending on the device vendor and Android version.
The initial application view:
Executing the following:
Will result in displaying a "Purchase successful" message:
Executing the following:
It will result in displaying the authentication request with a failure message.
Clearing the mocked reply
To set a different reply or to reset the mocked authentication reply state, close the dialog if open and then execute :
This result in displaying the original dialog, which is waiting for real user authentication:
The application used in the examples demonstrates the use of the new Biometric API, which replaces FingerprintManager, which is deprecated since API level 28.
- Introduction of Biometric API in Android Developers Blog
- BiometricPrompt documentation
- FingerprintManager documentation
Set the reply of the authentication attempt by using the SetAuthenticationReply command.
For example, Select the Error: AuthenticationFailedError, this will simulate the result of three bad authentication attempts (or more depending on the app definitions).
Here, we set the delay to 0 to prevent any delay before the response (after the request).
In case the application requests authentication upon launch, it is required to pre-set the desired reply as a launch environment using Launch With Options.
For example, if com.company.MyApp presents the on-screen authentication pop-up as soon as it launches, and we want to respond with a successful authentication, we would write the following in our test:
The list of supported error replies, along with their meaning, can be found in Apple's documentation: https://developer.apple.com/reference/localauthentication/laerror.code