MoeMail
Back to Blog

Automate Email-Verification Testing (Playwright, Cypress, Selenium)

Signup and password-reset flows are notoriously hard to test, because the critical step — the verification email — leaves your app. The fix is to give every test run its own disposable inbox it can read from code. This guide shows the pattern with Playwright, Cypress, and Selenium, built on a disposable email API.

Why email tests are flaky

Email is asynchronous: it travels through SMTP servers and can take seconds to arrive, while tests expect fast, deterministic results. Sharing one human mailbox across runs causes cross-talk and stale messages. The cure is create email on demand — provision a fresh, routable address per test, then consume its messages through an API.

The pattern

  1. Provision a temporary mailbox at test start (random or custom address).
  2. Drive your UI to the point that triggers the verification email.
  3. Await the message — poll the inbox, or react to a webhook for zero-latency delivery.
  4. Extract the verification link or one-time code from the message body.
  5. Continue the flow (click the link / enter the code) and assert success.

Keep it DRY: a reusable helper

Don't scatter inbox API calls across every spec. Wrap create / await / extract in one module: a Playwright fixture, a Cypress custom command, or a Selenium helper class. Tests then read like "create inbox, sign up, await verification, assert" — no transport details leaking into assertions.

Framework notes

  • Playwright — expose the helper as a fixture so each test gets a fresh inbox automatically; use web-first expect.poll while waiting for the message.
  • Cypress — wrap the API calls in cy.task or a custom command; avoid arbitrary cy.wait in favor of polling until the message arrives.
  • Selenium — put create/poll/extract in a page-object-style helper and use an explicit wait for the message.

Tips for reliability

Prefer webhooks over tight polling to cut latency and request count. Give each run a unique address so parallel tests never collide. Watch your monthly API quota in large suites — reuse an inbox across assertions where it's safe, and back off your poll interval. Authenticate every call with your API key in the X-API-Key header.

Get started

Grab an API key from your profile, read the OpenAPI docs, and wire a single fixture that creates an inbox and waits for one message. New to disposable inboxes? Start with what is temporary email.