Agent Wranglers

End-to-end and browser tests Required

Wait for the page to be ready instead of sleeping

In every asynchronous test, wait for a condition, such as a heading appearing or a queue emptying. Never pause for a fixed time.

How to do it

Use assertions that retry until they pass or time out, such as Playwright's expect(locator).toBeVisible(). Wait for a network response when that is the signal. Delete every sleep, waitForTimeout and time.sleep from browser tests. Server tests follow the same rule. Poll for the state you expect, with a timeout.

Example

// Bad: slow when the app is fast, flaky when it is slow
await page.waitForTimeout(3000);

// Good: waits exactly as long as needed
await expect(page.getByText('Order confirmed')).toBeVisible();

How to check

Search all tests for fixed waits, such as sleep, waitForTimeout or a bare setTimeout used as a pause. There are none.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests/no-sleeps.