Aller au contenu principal
GUIDE DE TESTS E2E · PLAYWRIGHT

Vérifiez vos e-mails OTP dans Playwright sans attentes aléatoires ni SaaS coûteux.

Allouez une boîte isolée par test Playwright via POST /v1/mailboxes, attendez message.ready via Fetch SSE, extrayez le code OTP et nettoyez en fin de test.

Workflow déterministe en 3 étapes

1. Provisionner par test

POST /v1/mailboxes renvoie une adresse unique et son access_token Bearer.

2. Écouter le flux SSE

GET /v1/mailboxes/me/events signale message.ready dès l’arrivée.

3. Extraire et nettoyer

Lisez GET /v1/mailboxes/me/messages/{id} puis appelez DELETE /v1/mailboxes/me.

Modèle Playwright prêt à copier

TypeScript
import { 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}` },
    });
  }
});

Workers CI parallèles ? Créez 1–20 boîtes par lot avec Pro

Avec Pro (1,99 $/mois ou 8,99 $ à vie), provisionnez jusqu’à 20 boîtes parallèles en un seul appel API sur des domaines isolés.

POST https://api.inboxflick.com/v1/member/mailboxes/batch
Authorization: Bearer <PRO_MEMBER_JWT>
Content-Type: application/json

{ "count": 20, "is_permanent": false }

Passez vos tests CI parallèles à l’échelle pour 8,99 $ à vie

Création illimitée, API par lots 1–20, domaines Pro isolés et 10 000 boîtes permanentes.

cypress vitest pytest API Pro

FAQ Tests E-mail CI

Faut-il installer un SDK spécifique pour Playwright ?
Non, fetch() ou requests standard suffit pour appeler /v1.
Comment gérer plusieurs workers CI en parallèle ?
Utilisez POST /v1/member/mailboxes/batch avec un JWT Pro.
Les liens magiques et le HTML sont-ils pris en charge ?
Oui, text_body et html_body assaini sont tous deux disponibles.