Page tree
Skip to end of metadata
Go to start of metadata

SetAuthenticationReply(Reply, Delay)

Supported only on devices that allow TouchID

Supported in iOS Supported in Android

Description

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. 

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


Android

Prior to instrumentation, you need to configure either of the following app properties :

  1. Set the android.instrument.fingerprint as true if your app implements a standard fingerprint authentication dialog.
  2. 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:

Note:

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.

Examples 

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:

Success result:

Executing the following:

Will result in displaying a "Purchase successful" message:

Mock Success Reply
client.setAuthenticationReply("AUTHENTICATION_SUCCEEDED", 0);
 
client.click("NATIVE", "xpath=//*[@text='PURCHASE']", 0, 1);


Failure result

Executing the following:

Mock Failure reply
client.setAuthenticationReply("AUTHENTICATION_FAILED", 0);

client.click("NATIVE", "xpath=//*[@text='PURCHASE']", 0, 1);

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 :

Clear Mock Reply
client.setAuthenticationReply("CLEAR_MOCK", 0); 

client.click("NATIVE", "xpath=//*[@text='PURCHASE']", 0, 1);

This result in displaying the original dialog, which is waiting for real user authentication:


More information

The application used in the examples demonstrates the use of the new Biometric API, which replaces FingerprintManager, which is deprecated since API level 28.

iOS

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

Note:

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.

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);
}

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





  • No labels