This guide shows how to run an OTP test for SMS-based MFA using Playwright.

Quick answer: what is an OTP test?

An OTP test validates that one-time passcodes are sent, received, parsed, and accepted correctly during sign-up or login workflows.

Why automate OTP tests?

  • Authentication is a release-critical path
  • Manual OTP testing is slow and inconsistent
  • Real phone number flows expose production-like failure modes

Test flow overview

  1. Create a test phone number
  2. Open application sign-up page with Playwright
  3. Submit registration form
  4. Wait for inbound SMS OTP code
  5. Enter code and confirm successful login

In this guide we use a demo SMS auth app at playground-sms.mailslurp.com.

Playwright setup

Create project

Install Playwright

Implement OTP test with Playwright

Load sign-up page

Fetch a test phone number

Fill and submit registration form

Wait for SMS and extract OTP

Submit OTP and verify account access

Cross-framework note

The same OTP test pattern works in Cypress and Selenium:

  • Create controlled number
  • Trigger auth flow
  • Wait for code
  • Assert confirmation success

See email and SMS testing guides for related workflows.

SMS OTP release checklist

Before shipping authentication changes, verify this sequence:

Final take

A reliable OTP test should run in CI for every release candidate. When auth flows break, users cannot onboard or sign in, so this is one of the highest ROI test suites to automate.