Cypress Email Tests Need a Freshness Gate
说明与用途
Cypress 邮件测试常因从共享收件箱中选取旧邮件而导致错误失败。文章提出“新鲜度门”方案:记录触发时间,轮询收件箱获取比该时间更新的邮件,并验证收件人、主题及可选测试标记,确保使用正确的邮件。
问题
Email tests can select an old message from a shared inbox, leading to wrong test failures.
结果
Adding a freshness gate reduces false failures caused by stale emails and provides clear evidence for debugging.
工作流
- Record trigger time before sending email request.
- Send email trigger request (e.g., password reset).
- Poll inbox using a helper that filters messages by receivedAt > trigger time, to=recipient, and subject match.
- If a fresh, owned message is found, accept it and continue; otherwise retry until timeout.
- Fail with detailed evidence if no fresh message is found.
证据
An email test can find a message and still be wrong. This happens when a shared inbox contains an older verification email, the test selects the newest result without checking its age, and the browser follows a link that belongs to another run.
Capture the time immediately before the action that should cause delivery. Then make freshness one of the acceptance rules, along with recipient, subject, and a unique test marker when the application supports one.
Keep polling, filtering, and diagnostics in a custom command or helper. The spec should say what the user is doing, while the helper explains why a candidate was accepted or rejected.
- 记录日期: 2026-11-02T09:59:12.105Z