SeeTestAutomation - SetAuthenticationReply(Reply, Delay) - TouchID
Please note that this tool is classified as a Legacy tool. We recommend transitioning to our updated solutions to maintain optimal performance and security in your workflows. For more information on this matter, please reach out to technical support .
SetAuthenticationReply(Reply, Delay)
Supported only on devices that allow TouchID
Description
Simulates different authentication responses on applications that request a user fingerprint authentication. This method allows you :
- in iOS: to set the desired response type for later authentication requests.
- in Android: to send the desired authentication response type when the app has already started to listen to touch IDs (i.e. authentication request dialog is open).
By doing so, you can verify the response of your application in different authentication scenarios.
In a nutshell, this is a mock authentication command.
Parameters-
-
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 ).
- In Android, prior to instrumentation, you need to configure either of the following app properties :
- android.instrument.fingerprint = true: use this if your app implements a standard fingerprint authentication dialog.
- android.instrument.fingerprint.secure = true: use this if your fingerprint implementation involves security authentications for the responses received from the user.
- In Android, After instrumenting the Application with mock authentication property the application may not support manual authentication (can't authenticate with 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
- 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: Launch and Authenticate
@Test
public void launchAndAuthenticate() {
// Create Map for the Authentication configuration Environments
Map<String, String> env = new HashMap<>();
// "0" - Default behavior (no mocking involved).
// "1" - Mock successful authentication
// "2" - Show All option in the application UI (can be used for test development).
// "-1" - "-9" Mock authentication errors (See link below for more details).
String authValue = "1";
env.put("EXPERI_MOCK_AUTH_HANDLE_CODE", authValue);
// Wait 1000 milliseconds before responding to application's authentication request:
env.put("EXPERI_MOCK_AUTH_HANDLE_DELAY_MILLIS", "1000");
// Create Map object for the launch command
Map<String, Object> launchOptions = new HashMap<>();
launchOptions.put("launch_env", env);
// Equivalent to stopIfRunning = true, to force fresh instance of the application (otherwise the environment might be ignored).
launchOptions.put("relaunch", true);
// Send the launch command to the device
client.launch("com.company.MyApp", launchOptions);
}
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
-
Use setMockAuthenticationReply with your desired authentication response when the authentication request dialog pops up:
-
For Example, choosing AUTHENTICATION_SUCCEED reply will simulate a fingerprint authentication success and will enable you to proceed with your test and access the data provided for an authentication success.
-
-
Please, read more on FingerprintManager.AuthenticationCallback for Android possible authentication responses and FingerprintManager for more info about the error codes and Image-acquisition messages.