How to Test Otp Verification on Web (Complete Guide)

One-Time Password (OTP) verification is a critical security layer for many web applications, safeguarding user accounts and sensitive transactions. Ineffective OTP implementation directly impacts user

March 27, 2026 · 6 min read · How-To Guides

Robust OTP Verification Testing for Web Applications

One-Time Password (OTP) verification is a critical security layer for many web applications, safeguarding user accounts and sensitive transactions. Ineffective OTP implementation directly impacts user experience, leading to account lockouts, failed transactions, and a significant erosion of trust. Thorough testing of OTP flows is not optional; it's a foundational requirement for secure and reliable web services.

Common OTP Verification Pitfalls

Users encounter problems when OTP systems fail in several predictable ways:

Comprehensive OTP Verification Test Cases

A robust testing strategy requires covering a range of scenarios.

#### Happy Path Scenarios

  1. Successful Verification:
  1. Resend OTP (Within Limit):
  1. Auto-Submit OTP (if applicable):

#### Error Scenarios

  1. Invalid OTP Entry:
  1. Expired OTP Entry:
  1. Exceeding Resend Limit:
  1. No OTP Received:
  1. Special Characters/Empty Input:

#### Edge Cases

  1. Simultaneous OTP Requests:
  1. Interruption During Verification:

#### Accessibility Considerations

  1. Screen Reader Compatibility:
  1. Keyboard Navigation:

Manual Testing Approach for OTP Verification

  1. Scenario Setup: Ensure you have access to the user's registered email or phone number for receiving OTPs.
  2. Initiate OTP Request: Navigate to the page requiring OTP verification (e.g., login, password reset, payment confirmation). Click the "Send OTP" or equivalent button.
  3. Receive and Record OTP: Check the designated channel (email inbox, SMS app) for the OTP. Note the exact code and its validity period if displayed.
  4. Enter Valid OTP: Input the received OTP into the provided field and click "Verify" or "Submit."
  1. Test Invalid OTP: Repeat step 3, but enter a deliberately incorrect OTP.
  1. Test Expired OTP: Wait for the OTP to expire (check its validity period). Attempt to enter the previously received OTP.
  1. Test Resend Functionality: After an OTP has expired or been invalidated, click the "Resend OTP" button.
  1. Test Rate Limiting: Repeatedly click "Resend OTP" within a short period, exceeding the defined limit.
  1. Test Input Validation: Try entering non-numeric characters, spaces, or leaving the field empty.
  1. Accessibility Checks: Use a screen reader and keyboard-only navigation to perform the key steps of the OTP flow.

Automated Testing for Web OTP Verification

Automating OTP verification presents a unique challenge: receiving the OTP.

Example (Conceptual Playwright - fetching from Mailtrap.io):


// Requires a Mailtrap client library and configuration
const { MailtrapClient } = require('mailtrap');
const client = new MailtrapClient({ token: 'YOUR_MAILTRAP_TOKEN' });

async function getLatestOtp(emailAddress) {
    try {
        const inbox = await client.getInbox('YOUR_INBOX_ID'); // Get your specific inbox ID
        const messages = await inbox.getMessages({ limit: 1, from: 'no-reply@yourdomain.com' }); // Filter by sender

        if (messages.length > 0) {
            const emailBody = messages[0].text_content || messages[0].html;
            // Regex to extract OTP (adjust based on your email format)
            const otpMatch = emailBody.match(/Your verification code is: (\d{6})/);
            if (otpMatch && otpMatch[1]) {
                return otpMatch[1];
            }
        }
    } catch (error) {
        console.error("Error fetching OTP from Mailtrap:", error);
    }
    return null;
}

// In your test:
const page = await browser.newPage();
await page.goto('https://your-app.com/login');
await page.click('button:has-text("Send OTP")');

let otp = null;
for (let i = 0; i < 10; i++) { // Retry fetching for a few seconds
    otp = await getLatestOtp('testuser@example.com');
    if (otp) break;
    await page.waitForTimeout(2000); // Wait 2 seconds before retrying
}

if (otp) {
    await page.fill('input[name="otp"]', otp);
    await page.click('button:has-text("Verify")');
    // Assert successful login/verification
} else {
    throw new Error("Failed to retrieve OTP");
}

SUSA's Autonomous OTP Verification Testing

SUSA automates OTP verification testing by integrating with these underlying mechanisms and leveraging its persona-driven exploration.

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free