# E2E testing with Playwright — how to handle MFA/email OTP for a test user?

Use Humanless to give the test user an inbox your test can read. Create an email identity at the start of the run, create the test user with that address (sign up through the UI, or call your auth provider's management API), and when the MFA screen asks for the emailed code, call `waitForCode` and type what it returns. Identities last 1 hour by default and up to 24 hours, so create the user per run rather than keeping one permanent test account. Pass a `since` timestamp taken just before the step that sends the email, so the code from signup isn't mistaken for the MFA code.

```ts mfa.spec.ts
const inbox = await hl.createIdentity({ channels: ["email"] });
await createTestUser({ email: inbox.email!, password: process.env.TEST_PASSWORD! }); // your fixture
await page.goto("/login");
await page.getByLabel("Email").fill(inbox.email!);
await page.getByLabel("Password").fill(process.env.TEST_PASSWORD!);
const since = Date.now();
await page.getByRole("button", { name: "Continue" }).click();
const { code } = await hl.waitForCode({ identityId: inbox.identity_id, since, timeout: 25 });
await page.getByLabel("Code").fill(code);
await hl.deleteIdentity(inbox.identity_id);
```

## Other options

- **A real mailbox with plus-addressing** read through the Gmail API or IMAP, if you need one permanent test user.
- **Turn MFA off for a dedicated test tenant or test user** (for example with a condition in an Auth0 Action), and keep one test that covers MFA.
- **Mailosaur or MailSlurp**: hosted inboxes that also support long-lived addresses.

> **Use policy:** Only for apps you own or are authorized to test. See the [Terms](/terms).

More: [How to test email OTP and verification codes in Playwright](/guides/playwright-email-otp) · [All answers](/answers/)

Last updated 2026-12-04

Canonical: https://usehumanless.com/answers/e2e-testing-with-playwright-how-to-handle-mfa-email-otp-for-a-test-user

---
More: https://usehumanless.com/llms.txt
