Waits and Timing
Learn when to wait, when not to wait, and why timing can break tests.
What you'll learn
- Avoid random sleep.
- Wait for a real condition.
- Spot timing problems fast.
Playwright AutomationlessonsJump to another lesson
Waits and Timing
Learn when to wait, when not to wait, and why timing can break tests.
Big Picture
One small picture can make this idea easier to hold.
Real wait
- Waits for visible state.
- Stops as soon as ready.
- Handles small delays.
- Shows the real problem.
Fake wait
- Sleeps for a guess.
- May waste time.
- Can still fail later.
- Can hide slow code.
VerdictWait for the thing you need. Do not wait longer just because you can.
How It Moves
Short steps make the flow easier to see.
See the risk
Find where timing might change the result.
Choose a condition
Wait for visible, enabled, or loaded state.
Avoid guesses
Skip long fixed pauses if you can.
Verify again
Confirm the app is ready before the next step.
Step By Step
This is the same idea, stretched across time.
- 1
Trigger change
Click or load the part that may take time.
- 2
Wait for state
Watch for the exact thing you need.
- 3
Move on
Continue when the state is ready.
- 4
Check the next step
Make sure the test is still stable.
One Small Model
Think of this like a tiny card you can keep in your pocket.
Wait plan
5 fieldsQuick Check
Why is page.waitForTimeout often a weak choice?
Map It
One more picture helps you see where this lesson matters most.
Timing choice map
Best
Wait for visible
Okay
Short timeout with reason
Weak
Long sleep
Avoid
Sleep before every step