ShazaMail
Test OTP Email Verification with Playwright
Email verification is an asynchronous part of a browser journey. A Playwright test should wait for the expected message, not guess how long delivery takes.
Product documentation last reviewed: 2026-11-18
Create an isolated inbox for each test
Give each test or CI worker its own inbox. Reusing a shared address makes parallel tests compete for messages and can cause one test to consume another test's code. Create the inbox through the developer API before submitting the signup form, and associate it with a run identifier that helps you trace failures. Keep API keys in your CI secret store and grant only the scopes the test needs.
Wait for the expected message, not an arbitrary delay
A fixed sleep such as waitForTimeout(10000) makes the suite slow when email arrives quickly and flaky when it arrives slowly. Prefer a bounded polling operation that waits for a message matching the test inbox and expected sender or subject. Set an explicit deadline, report the inbox identifier when the deadline expires, and avoid unlimited retries. The test should fail with a useful delivery diagnostic instead of silently moving on.
Extract and submit the one-time code carefully
Retrieve the message only after it has arrived, then use the platform's verification-code extraction where available. Assert that the code exists and is non-empty before filling the OTP field. Do not print the code, the whole email, or the API key into CI logs. Treat verification codes as short-lived credentials and avoid storing them in screenshots or test artifacts that are shared broadly.
Make cleanup and retries predictable
Use a unique idempotency key when creating resources that may be retried after a network timeout. Retry only transient operations with a bounded backoff, and distinguish a missing email from an application validation failure. At the end of the test, expire or release test resources according to your retention policy. The result is a Playwright journey that is easier to debug locally and more repeatable in CI.