Playwright Email Tests Need a Clock Contract
说明与用途
使用时间合同的 Playwright 电子邮件验证测试自动化方案,确保邮箱所有权、时序和证据,降低 CI 中的不可预测性。
问题
Email verification tests are flaky because the mailbox contract is missing, causing timing and ownership issues across local runs and CI.
结果
Deterministic email verification tests with reduced flakiness, clear ownership, and reproducible evidence.
工作流
- Reserve a mailbox with a unique lease ID and expiry
- Use the lease to poll for the expected email with subject and run ID
- Wait for the verification link to appear and return it
- Navigate to the link and assert account activation
- Release the mailbox lease in a finally block to ensure cleanup
证据
Email verification tests often look flaky for mysterious reasons. A user is created, the application sends a message, Playwright opens an inbox, and the test waits for a link.
The test can fail at every boundary. The application may queue the email after the HTTP response. The inbox may expose the message before its body is fully available.
Define the email clock contract… Reserved, Requested, Observed, Consumed…
The example keeps cleanup in finally, which matters when an assertion fails.
- 记录日期: 2026-10-18T06:41:14.045Z