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