Playwright email & OTP verification without flaky sleeps or expensive SaaS.
Give every Playwright test case an isolated disposable inbox via POST /v1/mailboxes, await message.ready deterministically over Fetch SSE, extract your OTP or magic link, and tear down cleanly.
3-Step Deterministic Workflow
1. Provision per test
Call POST /v1/mailboxes to receive a unique address and 256-bit Bearer access_token.
2. Stream SSE event
Subscribe to GET /v1/mailboxes/me/events with Authorization: Bearer until message.ready arrives.
3. Extract & clean up
Read GET /v1/mailboxes/me/messages/{id} for text/HTML and DELETE /v1/mailboxes/me in teardown.
Copy-Ready Playwright OTP Verification Template
TypeScriptimport { test, expect } from '@playwright/test';
const API = 'https://api.inboxflick.com/v1';
async function waitForOtp(token: string, timeoutMs = 30_000): Promise<string> {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
try {
const res = await fetch(`${API}/mailboxes/me/events`, {
headers: { Authorization: `Bearer ${token}` },
signal: controller.signal,
});
const reader = res.body!.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const match = buffer.match(/event: message\.ready\s+data: (\{[^\n]+\})/);
if (match) {
const { message_id } = JSON.parse(match[1]);
const msg = await fetch(`${API}/mailboxes/me/messages/${message_id}`, {
headers: { Authorization: `Bearer ${token}` },
}).then((r) => r.json());
const otp = msg.data.text_body.match(/\b(\d{6})\b/)?.[1];
if (otp) return otp;
}
}
} finally {
clearTimeout(timer);
controller.abort();
}
throw new Error('Timed out waiting for OTP email');
}
test('signup verifies 6-digit OTP email', async ({ page }) => {
const created = await fetch(`${API}/mailboxes`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: '{}',
}).then((r) => r.json());
const { address } = created.data.mailbox;
const token = created.data.access_token;
try {
await page.goto('/signup');
await page.getByLabel('Email').fill(address);
await page.getByRole('button', { name: 'Continue' }).click();
const otp = await waitForOtp(token);
await page.getByLabel('Verification code').fill(otp);
await expect(page).toHaveURL(/dashboard/);
} finally {
await fetch(`${API}/mailboxes/me`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${token}` },
});
}
}); Running Parallel CI Workers? Batch-Create 1–20 Inboxes with Pro
Guest IPs allow 1 active inbox at a time (5/day). Upgrade to Pro ($1.99/mo or $8.99 one-time lifetime) to provision 1–20 parallel worker mailboxes in a single API call on isolated clean domains.
POST https://api.inboxflick.com/v1/member/mailboxes/batch
Authorization: Bearer <PRO_MEMBER_JWT>
Content-Type: application/json
{ "count": 20, "is_permanent": false } Scale parallel CI email tests for $8.99 one-time
Unlock unlimited daily creation, 1–20 batch provisioning, isolated Pro domains, and 10,000 permanent inboxes.