---
title: "Wait for the page to be ready instead of · Agent Wranglers"
url: https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests/no-sleeps
updated: 2026-10-20
licence: "All rights reserved"
---

# Wait for the page to be ready instead of sleeping

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [End-to-end and browser tests](https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests)
- Rule: In every asynchronous test, wait for a condition, such as a heading appearing or a queue emptying. Never pause for a fixed time.
- How: 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.
- Check: Search all tests for fixed waits, such as `sleep`, `waitForTimeout` or a bare `setTimeout` used as a pause. There are none.

Example:

```js
// 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();
```

```python
# Bad
page.wait_for_timeout(3000)

# Good: Playwright for Python retries until the text appears
expect(page.get_by_text("Order confirmed")).to_be_visible()
```

**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`.

- Previous: [Find elements the way people do](https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests/stable-selectors)
- Next: [Run browser tests against the production build](https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests/test-the-built-app)
- [End-to-end and browser tests](https://agentwranglers.se/playbook/testing/end-to-end-and-browser-tests)
