Playwright Email Tests Need a Cleanup Contract
Описание и применение
Внедрение контракта владения почтовым ящиком в Playwright устраняет непредсказуемость тестов, обеспечивая явную очистку и диагностику ошибок, связанных со старыми или пересекающимися письмами.
Задача
Email-based end‑to‑end tests become flaky because tests share a mailbox and fail to clean up, leading to stale or cross‑run messages.
Результат
Implementing a mailbox ownership contract reduces flaky email tests, provides observable cleanup, and enables precise failure classification (stale-message, cross-run-collision, etc.).
Рабочий процесс
- 1. Test leases a mailbox with owner, runId, and lease timestamp.
- 2. Test performs signup using the leased address.
- 3. Test waits for a message containing a unique token after the lease time.
- 4. Test asserts message content and releases the mailbox in a finally block.
- 5. Server‑side reaper expires abandoned leases; CI publishes lease statistics.
Доказательства
Email-based end-to-end tests often look flaky for the wrong reason. A signup test creates a user, waits for a verification message, and sometimes finds an email that belongs to a previous run.
A reliable fixture should answer four questions before the browser opens the signup page: Who owns it? What can be read? How long can it live? Who cleans it?
Use a fixture that records its state and always attempts release in teardown.
If the browser process is killed, teardown may never run. The mailbox service needs a lease expiry and a reaper, and the CI job should publish counts for active, released, and expired leases.
- Дата записи: 2026-10-23T00:26:19.499Z