Playwright Email Tests Need Deterministic Polling
说明与用途
确定性轮询和唯一消息所有权使 CI 中的电子邮件验证测试可靠且可重复。
问题
Email verification tests in CI become flaky due to unpredictable message arrival, shared inboxes, and fixed waits.
结果
Deterministic polling with unique identities and structured receipts eliminates flakiness, provides clear failure diagnostics, and keeps secrets out of logs.
工作流
- 1. Generate a unique recipient or alias including worker index and run ID. 2. Add a non‑secret correlation ID to the email request. 3. Implement a mail adapter exposing a fetchMail function that retrieves only the current recipient’s messages. 4. Create a waitForMail helper that polls fetchMail until a predicate matches or a timeout occurs. 5. In the Playwright test, create the address, submit the form, and call waitForMail with a predicate matching subject and timestamp. 6. Extract the verification URL from the email body and navigate to it. 7. Assert the verification success message. 8. On timeout, generate a structured receipt containing run ID, recipient hash, attempt count, provider status, and request ID (excluding live tokens or full email body).
证据
A bounded polling loop, a unique test identity, and a small failure receipt remove most of the guesswork.
The important choices are the deadline and the predicate.
- 记录日期: 2026-09-22T20:30:42.240Z