Playwright와 Cypress를 활용한 E2E 이메일 테스트 — Gmail 자격 증명 필요 없음
Source: Dev.to
개요
Playwright 테스트가 “Reset Password” 버튼을 클릭합니다. 이메일이 전송됩니다. 이제 어떻게 할까요?
대부분의 팀은 모의 SMTP나 MailHog를 사용해 이를 가짜로 처리합니다. 로컬에서는 테스트가 통과하지만, 실제 스테이징 환경에서는 이메일이 전혀 도착하지 않아 테스트가 실패합니다. 더 나은 방법이 있습니다.
실제 테스트 인박스 만들기
brew install nylas/nylas-cli/nylas
nylas init
nylas inbound create e2e-testnylas inbound create 명령은 실제 이메일을 받을 수 있는 관리형 이메일 주소를 프로비저닝합니다. MX 레코드나 메일 서버가 필요 없습니다.
테스트에서 메시지 폴링하기
nylas inbound messages 명령은 새로운 메일을 확인합니다:
nylas inbound messages inbox_abc123 --unread --json --limit 1JSON 출력을 파싱해 비밀번호 재설정 링크, 인증 코드, 확인 이메일 등을 추출합니다.
실시간 모니터링
nylas inbound monitor 명령은 메일이 도착할 때마다 스트리밍합니다:
nylas inbound monitor inbox_abc123 --tunnel cloudflaredOTP 코드 추출
2단계 인증을 테스트하고 있나요? nylas workflow otp list 명령은 일회용 비밀번호를 추출합니다:
nylas workflow otp list --limit 1모든 테스트 인박스 목록 보기
nylas inbound list 명령은 관리 중인 주소들을 보여줍니다:
nylas inbound list --jsonMailHog를 사용하지 않는 이유
MailHog는 로컬에서 SMTP를 가로채기 때문에 애플리케이션이 MailHog를 통해 메일을 보내도록 설정해야 합니다. Nylas Inbound 주소는 실제 인프라를 통해 이메일을 받습니다. 여기로 메일이 도착하면 Gmail에서도 동일하게 도착합니다.
CI 통합
- name: Install Nylas CLI
run: curl -fsSL https://cli.nylas.com/install.sh | bash
- name: Run E2E tests
env:
NYLAS_API_KEY: ${{ secrets.NYLAS_API_KEY }}
run: |
nylas auth config --api-key $NYLAS_API_KEY
npx playwright test웹훅 테스트
nylas webhook test send 명령은 테스트 이벤트를 전송합니다:
nylas webhook test send https://staging.myapp.com/hooks/emailnylas webhook server 명령은 로컬 수신기를 시작합니다:
nylas webhook server --port 4000모든 명령어: Nylas CLI Command Reference
시작하기: brew install nylas/nylas-cli/nylas — 다른 설치 방법