What a passing test checks
A “check your email” screen confirms that your app accepted the request. This test also checks that the message arrives, the link opens the correct reset form, and the new password works. Your app keeps its existing email sender. InboxIt receives the message and Playwright drives your app.
Set up a private test environment
- Use an app and test environment you control, with outbound transactional email enabled for the test. Set
TEST_APP_ORIGINto that environment’s origin. - Seed an active user without sending a welcome email. The example expects a test-only
POST /__test__/usersto accept an email and password and return an ID. It expectsDELETE /__test__/users/:idto remove the user. Replace these calls with your app’s fixture and keep the route out of production. StoreRESET_FIXTURE_TOKENin your runner’s secrets if you use the sample’s bearer-authenticated fixture. - Use Node.js 22 or newer and install Playwright and Chromium.
npm install -D @playwright/test
npx playwright install chromiumThe default InboxIt endpoint uses the receive-only public API and needs no workspace key. For local tests against a fixture, set INBOXIT_TEST_INBOX_URL to its full inbox endpoint.
Run the reset flow
Save this as tests/password-reset.spec.js. Adapt the page routes, field labels, email subject and reset URL to match your app. The example accepts a token made of letters, digits, underscores and hyphens. Use your app’s token format when validating the extracted link.
import { randomUUID } from 'node:crypto';
import { expect, test } from '@playwright/test';
test.use({ trace: 'off', screenshot: 'off', video: 'off' });
function requireOk(response, operation) {
if (!response.ok()) {
throw new Error(operation + ' failed (HTTP ' + response.status() + ')');
}
}
test('the reset email lets a test user sign in again', async ({ page, request, browser }) => {
test.setTimeout(150_000);
const origin = new URL(process.env.TEST_APP_ORIGIN).origin;
const fixtureToken = process.env.RESET_FIXTURE_TOKEN;
if (!fixtureToken) throw new Error('Set RESET_FIXTURE_TOKEN for your test app');
const inboxUrl = process.env.INBOXIT_TEST_INBOX_URL ?? 'https://api.inboxit.wtf/api/v2/public/inboxes';
const fixtures = new URL('/__test__/users', origin).href;
const fixtureHeaders = { Authorization: 'Bearer ' + fixtureToken };
const oldPassword = 'Before-' + randomUUID();
const newPassword = 'After-' + randomUUID();
const created = await request.post(inboxUrl, {
headers: { 'Idempotency-Key': randomUUID() }, maxRedirects: 0,
});
requireOk(created, 'Create test inbox');
const { token, inbox } = await created.json();
const headers = { Authorization: 'Bearer ' + token };
let userId;
let signIn;
let passed = false;
try {
await expect.poll(async () => {
const response = await request.get(inboxUrl, { headers, maxRedirects: 0 });
requireOk(response, 'Read test inbox');
return (await response.json()).inbox.status;
}, { timeout: 25_000, intervals: [500, 1_000, 2_000] }).toBe('active');
// Replace this with your app's test-only user fixture.
const seed = await request.post(fixtures, {
headers: fixtureHeaders, data: { email: inbox.address, password: oldPassword }, maxRedirects: 0,
});
requireOk(seed, 'Seed test user');
userId = (await seed.json()).id;
if (!userId) throw new Error('The fixture did not return a user ID');
await page.goto(new URL('/forgot-password', origin).href);
await page.getByLabel('Email', { exact: true }).fill(inbox.address);
await page.getByRole('button', { name: 'Send reset email' }).click();
await expect(page.getByText('Check your email', { exact: true })).toBeVisible();
const wait = new URL(inboxUrl + '/wait');
wait.searchParams.set('timeout', '3');
wait.searchParams.set('subject', 'Reset your password');
let links = [];
await expect.poll(async () => {
const response = await request.get(wait.href, { headers, maxRedirects: 0, timeout: 8_000 });
requireOk(response, 'Wait for reset email');
const result = await response.json();
if (result.status === 'matched') links = result.extraction.links;
return result.status;
}, { timeout: 75_000, intervals: [1_000] }).toBe('matched');
const resetLinks = [...new Set(links)].filter(value => {
if (!URL.canParse(value)) return false;
const url = new URL(value);
const token = url.searchParams.get('token') || '';
return url.origin === origin && url.pathname === '/reset-password' &&
/^[A-Za-z0-9_-]+$/.test(token);
});
if (resetLinks.length !== 1) throw new Error('Expected one reset link on the test app');
await page.goto(resetLinks[0]);
if (new URL(page.url()).origin !== origin) throw new Error('Reset page left the test app');
await page.getByLabel('New password', { exact: true }).fill(newPassword);
await page.getByLabel('Confirm password', { exact: true }).fill(newPassword);
await page.getByRole('button', { name: 'Update password' }).click();
await expect(page.getByText('Password updated', { exact: true })).toBeVisible();
signIn = await browser.newPage();
await signIn.goto(new URL('/sign-in', origin).href);
await signIn.getByLabel('Email', { exact: true }).fill(inbox.address);
await signIn.getByLabel('Password', { exact: true }).fill(newPassword);
await signIn.getByRole('button', { name: 'Sign in', exact: true }).click();
await expect(signIn.getByRole('heading', { name: 'Your account' })).toBeVisible();
passed = true;
} finally {
const cleanup = [request.delete(inboxUrl, { headers, maxRedirects: 0, timeout: 5_000 })];
if (userId) cleanup.push(request.delete(fixtures + '/' + encodeURIComponent(userId), {
headers: fixtureHeaders, maxRedirects: 0, timeout: 5_000,
}));
const results = await Promise.allSettled(cleanup);
await signIn?.close();
if (passed && results.some(result => result.status === 'rejected' || !result.value.ok())) {
throw new Error('The reset passed but fixture cleanup failed');
}
}
});npx playwright test tests/password-reset.spec.js --workers=1Each run uses a fresh inbox, so an older reset email can’t satisfy it. If you reuse an inbox for signup and reset, record the newest message ID before requesting the reset and pass it as the after cursor.
Handle timeouts, limits and secrets
- If provisioning stalls, check inbox status before submitting the form. If mail never matches, check your app’s sending logs and subject.
- The guest API allows up to three inbox creations per network per UTC day. CI workers can share that limit. Use authenticated workspace testing for a regular suite and respect
Retry-Afterwhen you receive a 429. - Keep inbox tokens, reset links and fixture credentials in the test runner. This example disables Playwright traces, screenshots and video. Redact the same values from your application and CI logs.
- Add separate tests for expired links, used links and rejection of the old password.
