Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

A Playwright Mailbox Lease for Reliable Tests

Описание и применение

Внедрение аренды почтового ящика в тестах Playwright устраняет непредсказуемость, обеспечивая уникальный адрес, идентификатор выполнения и временные метки, а также надёжную очистку после теста.

Задача

Email verification tests fail due to race conditions and shared inboxes, causing flaky results in CI environments.

Результат

The mailbox lease pattern eliminates flakiness by ensuring each test owns a unique inbox, filters messages by recipient, timestamp, and subject, and cleans up after itself, leading to more reliable CI test results.

Рабочий процесс

  • Create a mailbox lease before browser starts, including address, runId, createdAt, and expiresAt.
  • Use the lease address to fill the email field in the signup form.
  • Wait for a message matching the lease address, createdAt, and subject using waitForMessage.
  • Verify recipient and timestamp against the lease.
  • Extract the verification URL from the message text and navigate to it.
  • Assert the account verified page is visible.
  • Finally, release the mailbox lease in a finally block to clean up resources.

Доказательства

Email verification tests often fail for a reason that has nothing to do with the verification code. Two workers read the same inbox, a previous message wins the race, or cleanup happens before the test has captured its evidence.

Источник

A useful mental model is to treat a test mailbox as a short‑lived lease. One test owns it for one scenario, knows when the lease started, and can prove which message belongs to the run.

Источник

The important part is not the provider API. It is the sequence of checks around the API: recipient must match, the message must be newer than the lease, and the subject must identify the expected workflow.

Источник

Before the browser starts, create the lease. After the test finishes, release it in a finally block.

Источник

  • Дата записи: 2026-10-26T18:11:11.813Z