본문으로 건너뛰기
E2E 테스트 통합 가이드 · PLAYWRIGHT

Playwright에서 sleep 없이 정확하고 저렴하게 OTP 이메일 테스트하기.

각 Playwright 테스트마다 POST /v1/mailboxes로 격리된 임시 메일함을 생성하고 Fetch SSE로 message.ready 이벤트를 수신해 OTP를 추출하세요.

3단계 결정적 테스트 흐름

1. 테스트별 메일함 발급

POST /v1/mailboxes 호출로 고유 주소와 Bearer 토큰을 발급받습니다.

2. SSE 실시간 대기

GET /v1/mailboxes/me/events를 구독해 message.ready를 즉시 수신합니다.

3. 코드 추출 및 정리

메시지 본문에서 OTP를 파싱한 뒤 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)를 사용하면 한 번의 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 }

$8.99 평생권으로 병렬 CI 이메일 테스트 확장

일일 한도 무제한, 1–20 일괄 API 및 Pro 격리 도메인을 제공합니다.

cypress vitest pytest API Pro

CI 이메일 테스트 FAQ

Playwright용 별도 SDK 설치가 필요한가요?
아니요, 기본 fetch() 또는 requests만으로 바로 호출할 수 있습니다.
병렬 테스트 시 게스트 제한은 어떻게 해결하나요?
Pro JWT로 POST /v1/member/mailboxes/batch를 호출하면 됩니다.
매직 링크와 HTML 본문도 확인 가능한가요?
네, text_body와 정제된 html_body를 모두 반환합니다.