QA Automation & Testing Published 2026-08-13 • 9 min read

Automated End-to-End SMS Verification Testing with Playwright and Webhooks

Step-by-step tutorial: automate 2FA user onboarding and OTP verification in Playwright using SMSRiver's REST API and synthetic test numbers.

Key Takeaway & Executive Summary

Automate complete browser signup and 2FA authentication in Playwright test suites without physical handsets or manual OTP copy-paste.

End-to-end testing of user registration pipelines is notoriously difficult when the application mandates SMS verification. Testing teams frequently disable 2FA in staging or use brittle manual workarounds. This guide shows how to automate real SMS verification in Playwright suites.

1 The Playwright Automation Architecture

The test workflow operates in 4 automated steps:

1. Playwright opens the signup page, fills in credentials, and enters a provisioned test phone number.
2. Application sends OTP via SMS API.
3. Playwright polls SMSRiver's REST API (GET /api/v1/inbox/{phone}/messages/) or waits for webhook callback.
4. Playwright extracts the 6-digit regex token from the message body and inputs it into the browser verification form.

2 Playwright TypeScript Implementation

typescript
import { test, expect } from '@playwright/test';

test('User completes SMS verification onboarding', async ({ page }) => {
  const testPhone = '+12025550199';
  await page.goto('/signup');
  await page.fill('#phone-input', testPhone);
  await page.click('#submit-btn');

  // Poll SMSRiver API for latest received OTP
  const otpResponse = await fetch(`https://smsriver.com/api/v1/inbox/12025550199/messages/`, {
    headers: { 'Authorization': `Bearer ${process.env.SMSRIVER_API_KEY}` }
  });
  const data = await otpResponse.json();
  const otpCode = data.messages[0].body.match(/\b\d{6}\b/)[0];

  await page.fill('#otp-input', otpCode);
  await page.click('#verify-btn');
  await expect(page.locator('#dashboard')).toBeVisible();
});

Frequently Asked Questions • QA Automation & Testing

Can this test run concurrently in CI/CD parallel jobs?

Yes. Each parallel test worker can query a distinct test number from your SMSRiver private pool or inject synthetic SMS events dynamically.

Related Technical Articles & Deep Dives

Copied to clipboard