Play supports automating logins that require a time-based one-time password (TOTP) during MFA.
The supported flow is:
-
Store the shared MFA secret as a team secret.
-
Generate the TOTP at runtime with
leapwork.generateTOTP(). -
Fill the verification-code field with the generated value.
-
Submit the login form.
When to use this
Use this pattern when the application presents a verification-code prompt after the username and password step.
This works well for Salesforce and other apps that use authenticator-app based MFA.
Prerequisites
-
The MFA secret must already be enrolled in an authenticator setup.
-
Save the secret in Play as a team secret.
-
Use the secret name in your Playwright test instead of hardcoding the value.
Example
const otp = leapwork.generateTOTP(
leapwork.variables.getSecret("mfa-secret")
);
await page.getByLabel("Verification code", { exact: true }).fill(otp);
await page.getByRole("button", { name: "Verify code", exact: true }).click();
Notes
-
generateTOTP()is a runtime helper. It does not store or expose the secret in the test source. -
The generated code is time-based and changes frequently, so generate it immediately before filling the field.
-
If the app labels the field differently, target the visible label or accessible name used by the page.
-
For login flows where the verifier is an email code rather than authenticator-app TOTP, use the app-specific email verification flow instead.