The OTP module allows the generation of time-based one-time passwords (TOTP) for testing applications that use multi-factor authentication (MFA). This enables fully automated end-to-end testing of login flows that require authenticator app codes.
The module uses the industry-standard otplib library to generate 6-digit codes compatible with Google Authenticator, Microsoft Authenticator, Authy, and other TOTP-based authentication apps.
Installing OTP
Right-click Modules/Pages in the Rapise test tree.
Choose Import Public Page Object > OTP.
After installation, you will find OTP inside your Modules/Pages folder.
Configuring OTP
The OTP module requires a secret key to generate one-time passwords. You can provide the secret in several ways:
As a function parameter: Pass the secret directly to OTP.GetCode(secret)
As a global variable: Set global.g_OTP_Secret before calling the function
As a test parameter: Define an OTP Secret parameter in your test configuration
Obtaining the Secret Key
When setting up MFA for a test account, the target application typically displays a QR code along with a text-based secret key (also called a "setup key" or "manual entry key"). Copy this text-based secret key and use it in your Rapise tests.
Note: Keep your OTP secrets secure. Treat them like passwords—do not commit them to source control in plain text. Consider using Rapise parameters or environment variables to store them securely.
Usage Examples
Basic Usage in RVL

Basic Usage in JavaScript
// Using secret directly
var code = OTP.GetCode("JBSWY3DPEHPK3PXP");
Tester.Message("Generated OTP: " + code);
// Using global variable
global.g_OTP_Secret = "JBSWY3DPEHPK3PXP";
var code = OTP.GetCode();
// Using test parameter (set "OTP Secret" in test configuration)
var code = OTP.GetCode();
Complete Login Flow Example
// Navigate to login page
Navigator.Open("https://myapp.example.com/login");
// Enter username and password
SeS('Username').DoSetText("testuser@example.com");
SeS('Password').DoSetText("MyPassword123");
SeS('LoginButton').DoClick();
// Handle MFA challenge
var otpCode = OTP.GetCode("JBSWY3DPEHPK3PXP");
SeS('OTPInput').DoSetText(otpCode);
SeS('VerifyButton').DoClick();
// Verify successful login
Tester.Assert("User logged in successfully", SeS('Dashboard').Exists());
Technical Details
Automatic Dependency Installation
The OTP module automatically installs required Node.js dependencies (otplib) on its first use. The installation is performed using npm and the modules are safely stored in PageObjects\OTP\node_modules.
Time Synchronization
TOTP codes are time-based and change every 30 seconds. Ensure your test machine's clock is synchronized (using NTP) for reliable code generation. A time difference of more than a few seconds between your machine and the server may cause authentication failures.
Compatibility
The generated codes are compatible with:
API Reference
OTP.GetCode
Generates a 6-digit one-time password.
Parameters:
| secret | | | Secret key for OTP generation. If not provided, the function uses global.g_OTP_Secret or Tester.GetParam("OTP Secret"). |
Returns:
String containing the 6-digit OTP code, or an empty string if no secret is configured.
Troubleshooting
"OTP Secret is not defined" message
Ensure you provide the secret either as a parameter, a global variable, or a test parameter.
Code is rejected by the application
Verify the secret key is correct (check for typos or extra spaces).
Check that your local system clock is properly synchronized.
Ensure you are entering the code before it expires (codes are valid for ~30 seconds).
npm install errors
The module requires Node.js to be available. Rapise includes a bundled Node.js environment, but if you encounter issues, verify that your Rapise installation is fully complete.