Cypress Email Tests Need a Clear Handoff
说明与用途
Cypress 邮件测试常因浏览器与收件箱之间的隐式交接导致失败。文章提出明确的交接协议,记录收件箱地址、运行 ID、触发时间和邮件信息,使测试可预测并便于错误诊断。
问题
Email tests fail when the browser action that triggers an email is not clearly separated from the inbox observation, causing ambiguous timeouts and hidden failures.
结果
Tests become deterministic and failures are diagnosable; email receipts provide stable artifacts for CI and QA.
工作流
- Create a unique inbox for the test via a Cypress task
- Submit the registration form in the browser
- Record the trigger time immediately before submission
- Wait for the verification email using a Cypress task that polls the inbox
- Select a message that matches the inbox, trigger time, and subject and has not been claimed
- Return an EmailReceipt containing runId, inbox, triggeredAt, messageId, subject, receivedAt, and verificationUrl
- Assert the receipt’s messageId is a string
- Visit the verificationUrl to complete account activation
证据
Email tests usually fail at the point where a browser action becomes an inbox observation.
I treat the browser-to-inbox handoff as a test boundary.
The contract does not need a large framework. It needs clear inputs and a useful failure result.
The helper should reject stale messages instead of silently returning the newest message.
- 记录日期: 2026-10-13T00:41:03.371Z