# Email testing in Playwright

> A Playwright test that waits for an email, reads the code inside it and carries on. No sleep, no regular expression, and no package to install.
> https://facteur.eu/en/playwright-email-testing

## Your test waits for the mail. It does not sleep.

A sign-up journey ends in a mailbox. Without one the test can read, there are two options left: mock the mail away, which proves nothing about the part most likely to break, or loop on a fixed delay. Here is the third.

## The whole test

Nothing is trimmed: this is the complete file, and it imports Playwright only.

### The request goes out before the click

It stays open and answers the moment the mail lands, not at the deadline. Issued after the click, it would chase a message that may already have been handled.

### Every test has its own address

Everything after the "+" is yours and still arrives. Two tests running at once cannot steal each other’s mail, and nothing has to be created first.

### The code is already extracted

The message arrives with its one-time code in a field of its own. You are not rewriting the regular expression that sits in every test suite.

### Read status before anything else

An accepted email exists before it is parsed: for a few milliseconds it has no subject and no code. That field separates "there is no code in this message" from "the code is not extracted yet".

## Why this test fits in thirty lines

## The application that sends this email

The test above goes nowhere without an application that really sends the message, and yours may not be ready. La Belle Etoile is one, open to anyone: order a lamp, give it your test mailbox address, and the confirmation arrives with its code. No account to create, nothing to install. The shop only ever mails a Facteur address, which is what stops it being a relay for anyone else, and its code knows nothing about us: it behaves like your application rather than like a showcase.

## The Playwright plugin, if you want it

It installs in one line: npm i -D playwright-facteur. It derives one address per test, retries its assertions the way Playwright does, and attaches the message it received to the report, so a failure shows the mail that arrived instead of a red line on its own. The test above does not use it and keeps working: the plugin buys comfort, not capability.
