メインコンテンツへスキップ
E2E テスト統合ガイド · PLAYWRIGHT

Playwright で sleep() なし・低コストに OTP メール認証を自動テスト。

各 Playwright テストで POST /v1/mailboxes から独立した一時メールを発行し、Fetch SSE で message.ready を待機して OTP を抽出できます。

3ステップの決定的ワークフロー

1. テストごとに受信箱を作成

POST /v1/mailboxes で一意のアドレスと Bearer access_token を取得します。

2. SSE で即時待機

GET /v1/mailboxes/me/events を購読し message.ready イベントを受け取ります。

3. OTP 抽出と削除

GET /v1/mailboxes/me/messages/{id} を読み取り、最後に DELETE /v1/mailboxes/me を呼びます。

コピーして使える Playwright OTP テストコード

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

並列 CI 実行には Pro の 1〜20件一括 API を活用

Pro(月額 $1.99 / 買い切り $8.99)なら 1回の API 呼び出しで最大20件の並列受信箱と専用隔離ドメインを確保できます。

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

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

並列 CI メールテストを買い切り $8.99 で解放

1日の上限なし・1〜20一括 API・専用ドメイン・10,000件永久保持。

cypress vitest pytest API Pro

CI メールテスト FAQ

Playwright 専用の SDK パッケージは必要ですか?
不要です。標準の fetch() や Python requests だけで動作します。
並列テストでゲスト制限を回避するには?
Pro JWT を使って POST /v1/member/mailboxes/batch を呼び出してください。
マジックリンクや HTML メールも取得できますか?
はい、text_body とサニタイズ済み html_body の両方を返します。