Working test, run November 25, 2026
Temp mail for Playwright: test signups with a disposable inbox
By Waqar Habib Khan | Published 2026-11-25 | The spec below was executed locally before this page shipped
Quick answer
How do I use temp mail in a Playwright test?
- One inbox per test run: runs never share state and never flake on each other.
- One long-poll instead of a polling loop: the wait call counts as one API call.
- Needs a Premium, Developer, or Business API key: the Free plan returns 402.
How the test works
1. Create a fresh inbox. The test POSTs to /api/v1/inbox with an empty JSON body and gets a random address back, plus its expiry. It asserts the address matches the expected shape and expires in the future, so a broken API response fails fast instead of failing later at the form.
2. Prove the inbox starts empty. It calls the OTP endpoint before any mail exists. The endpoint answers 200 with message: null, which tells the test that empty inboxes are normal and distinct from a missing inbox (404).
3. Sign up. Playwright opens the signup URL, fills the email field with the disposable address, and submits. The URL and the selectors all come from environment variables, so the same spec runs against staging and production.
4. Wait, then read the code. The wait endpoint holds the request for up to 55 seconds until the verification mail lands. Then the OTP endpoint returns the code the server extracted from the message, so the test never parses an email body itself.
5. Enter the code and assert. The test fills the code field, submits, and waits for the success text. The inbox is never reused: the next run creates its own.
The full spec
Save it as temp-mail-playwright.spec.ts, or download the same file here: temp-mail-playwright.spec.ts. It was executed locally on November 25, 2026 against a stub that mirrors the real endpoint paths, status codes, and JSON shapes, with a fake signup page that sends a real verification code through the same flow; the live endpoints were probed the same day and return the documented 401 responses without a key. It has not been run end to end against the live API with a paid key in this environment, because no paid-plan key exists here: the first run with a real key is yours, and the test is written to make that run the same as the local one.
temp-mail-playwright.spec.ts
import { test, expect, request } from "@playwright/test";
const API_BASE = (
process.env.TEMPIFY_API_BASE ?? "https://tempify.org/api/v1"
).replace(//$/, "") + "/";
const API_KEY = process.env.TEMPIFY_API_KEY ?? "";
const SIGNUP_URL = process.env.SIGNUP_URL ?? "";
const EMAIL_SELECTOR =
process.env.SIGNUP_EMAIL_SELECTOR ?? 'input[type="email"]';
const SUBMIT_SELECTOR =
process.env.SIGNUP_SUBMIT_SELECTOR ?? 'button[type="submit"]';
const CODE_SELECTOR =
process.env.SIGNUP_CODE_SELECTOR ?? 'input[name="code"]';
const SUCCESS_TEXT = process.env.SIGNUP_SUCCESS_TEXT ?? "Welcome";
test.beforeAll(() => {
test.skip(
!API_KEY,
"Set TEMPIFY_API_KEY to run this test (Premium, Developer, or Business plan).",
);
});
test("temp mail signup: create inbox, sign up, wait for code, assert", async ({
page,
}) => {
const api = await request.newContext({
baseURL: API_BASE,
extraHTTPHeaders: { "x-api-key": API_KEY },
});
// 1. Create a fresh inbox for this test run only.
const created = await api.post("inbox", { data: {} });
expect(created.status(), "create inbox").toBe(201);
const createdBody = await created.json();
const address: string = createdBody.inbox.address;
expect(address).toMatch(/^[a-z0-9._-]+@[a-z0-9.-]+$/);
expect(new Date(createdBody.inbox.expires_at).getTime()).toBeGreaterThan(
Date.now(),
);
// The inbox starts empty: the OTP endpoint answers 200 with no message.
const empty = await api.get(`inbox/${encodeURIComponent(address)}/otp`);
expect(empty.status(), "otp on empty inbox").toBe(200);
expect((await empty.json()).message).toBeNull();
if (!SIGNUP_URL) {
// No app under test configured: prove the wait primitive works and stop.
// A 10 second wait on an inbox nobody mails to times out cleanly.
const waited = await api.get(
`inbox/${encodeURIComponent(address)}/wait?timeout=10`,
);
expect(waited.status(), "wait for mail").toBe(200);
const waitedBody = await waited.json();
expect(waitedBody.timed_out).toBe(true);
expect(waitedBody.messages).toEqual([]);
return;
}
// 2. Sign up with the disposable address.
await page.goto(SIGNUP_URL);
await page.locator(EMAIL_SELECTOR).first().fill(address);
await page.locator(SUBMIT_SELECTOR).first().click();
// 3. Wait for the verification mail (long-poll: one API call, up to 55s).
const arrived = await api.get(
`inbox/${encodeURIComponent(address)}/wait?timeout=55`,
);
expect(arrived.status(), "wait for verification mail").toBe(200);
const arrivedBody = await arrived.json();
expect(arrivedBody.timed_out, "verification mail arrived").toBe(false);
expect(arrivedBody.messages.length).toBeGreaterThan(0);
// 4. Read the code the server extracted from the latest message.
const otp = await api.get(`inbox/${encodeURIComponent(address)}/otp`);
expect(otp.status(), "read otp").toBe(200);
const otpBody = await otp.json();
expect(otpBody.otp, "verification code extracted").toMatch(/^\d{4,8}$/);
// 5. Enter the code and assert the signup completed. Re-query for the
// visible submit button: many signup flows hide the first form after
// submit, so the first matching button in the DOM may be hidden.
await page.locator(CODE_SELECTOR).first().fill(otpBody.otp);
await page.locator(SUBMIT_SELECTOR + ":visible").first().click();
await expect(page.getByText(SUCCESS_TEXT).first()).toBeVisible({
timeout: 10_000,
});
});Run it
The test skips itself with a clear message when TEMPIFY_API_KEY is not set, instead of failing with a confusing 401. Without SIGNUP_URL it runs the inbox half of the flow only: create, prove empty, and prove the wait times out cleanly on an inbox nobody mails to. That is the fastest way to check your key and the API wiring before pointing the test at a real signup form.
Run locally
TEMPIFY_API_KEY=your_key npx playwright test temp-mail-playwright.spec.ts
# Against staging, with custom selectors:
TEMPIFY_API_KEY=your_key \
SIGNUP_URL=https://staging.example.com/signup \
SIGNUP_SUCCESS_TEXT="Check your inbox" \
npx playwright test temp-mail-playwright.spec.tsRun it in CI (GitHub Actions)
Store the key as a repository secret called TEMPIFY_API_KEY and the signup URL as a variable called SIGNUP_URL. Never commit a key to the repository: a key in git history is a key anyone can use against your monthly allowance.
GitHub Actions
name: signup tests
on:
push:
branches: [main]
jobs:
signup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: npx playwright test temp-mail-playwright.spec.ts
env:
TEMPIFY_API_KEY: ${{ secrets.TEMPIFY_API_KEY }}
SIGNUP_URL: ${{ vars.SIGNUP_URL }}The API calls behind the test
Three inbox endpoints do all the work. The full reference, with error codes, rate limit headers, and the OpenAPI spec, is on the temporary email API page.
| Call | What the test uses it for | Cost |
|---|---|---|
| POST /api/v1/inbox | Create one inbox per run | 1 call |
| GET /api/v1/inbox/{address}/wait | Hold until the verification mail arrives (up to 55s) | 1 call, however long it holds |
| GET /api/v1/inbox/{address}/otp | Read the server-extracted code | 1 call |
A full run costs 3 to 4 API calls, so the Premium allowance of 1,000 calls a month covers roughly 250 signup tests. If your suite runs hotter than that, Business at $49 a month includes 50,000 calls. The test asserts on every API status, so a 402 (Free plan), 401 (bad key), or 429 (allowance exhausted) fails loudly at the step that caused it instead of surfacing later as a missing code.
Keep going
Temporary Email API
The full REST reference behind this test, with real limits and error codes.
Temp mail for QA automation
The use-case page for QA teams: when disposable inboxes fit the suite.
Temp mail for Cypress
The same signup test in Cypress, for teams that already run it.
Temp mail for Selenium
The same signup test in Selenium WebDriver, for cross-browser suites.
Developer hub
Every developer page: QA testing, app testing, and the API guides.
Temp mail for Playwright questions, answered
The questions QA engineers ask before adding this test to a suite.
Can I use temp mail in a Playwright test?
Yes. The test on this page creates a fresh Tempify inbox through the API, fills the signup form with that address, waits for the verification mail with the API long-poll endpoint, reads the extracted code, and asserts the signup completed. Every test run gets its own inbox, so runs never share state.
Do I need a paid plan to use temp mail in Playwright?
Yes. The test calls the Tempify API, and API access starts on Premium at $4.99 a month (1,000 calls a month). The Free plan returns 402 on every API call, so the test skips itself when no key is set and fails with 402 on a Free-plan key. The Developer plan at $19 a month with 10,000 calls a month is coming soon; Business at $49 a month includes 50,000 calls.
How does the test wait for the verification email?
It calls GET /api/v1/inbox/{address}/wait?timeout=55, which holds the request until a message arrives or 55 seconds elapse. One wait counts as one API call however long it holds, so the test does not poll in a loop and does not burn the monthly allowance. On timeout the response is 200 with timed_out true, and the test fails with a clear message instead of hanging.
How do I run this test in CI?
Save the spec file, add your API key as a repository secret called TEMPIFY_API_KEY, and run npx playwright test with TEMPIFY_API_KEY set from the secret. The CI snippet on this page shows the GitHub Actions job. The test reads the signup URL and selectors from environment variables, so the same spec runs against staging and production by changing variables, not code.
What if the verification email is slow?
The wait endpoint holds up to 55 seconds per call, which covers most verification mail. If your mailer is slower than that, call wait again with the since parameter set to the first call's start time: only messages after that timestamp are returned, so the second wait does not re-read old mail. Do not generate a new inbox and restart the signup: a new address restarts the sender's delivery clock.
Does the test work with Cypress or Selenium too?
The API calls are plain HTTP, so the same flow works in any framework: create the inbox with POST /api/v1/inbox, submit the form, wait with GET /api/v1/inbox/{address}/wait, and read the code with GET /api/v1/inbox/{address}/otp. Only the browser-driving code changes. The API reference at tempify.org/developers/temporary-email-api documents every call the test uses.