Waits and Timing

Learn when to wait, when not to wait, and why timing can break tests.

Playwright Automation Module 2 Lesson 4
10 min read

What you'll learn

  • Avoid random sleep.
  • Wait for a real condition.
  • Spot timing problems fast.

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.

1

See the risk

Find where timing might change the result.

Choose a condition

Wait for visible, enabled, or loaded state.

3

Avoid guesses

Skip long fixed pauses if you can.

4

Verify again

Confirm the app is ready before the next step.

Step By Step

This is the same idea, stretched across time.

  1. 1

    Trigger change

    Click or load the part that may take time.

  2. 2

    Wait for state

    Watch for the exact thing you need.

  3. 3

    Move on

    Continue when the state is ready.

  4. 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 fields
Event:"Save click"
Wait for:"Toast visible"
Timeout:"3s"
Risk:"Low"
Sleep:"None"
A good timing plan waits for one clear thing.

Quick Check

Question 1 of 10 correct

Why is page.waitForTimeout often a weak choice?

Map It

One more picture helps you see where this lesson matters most.

Timing choice map

Test quality
Reliable

Best

Wait for visible

Okay

Short timeout with reason

Weak

Long sleep

Avoid

Sleep before every step

Slow
GuessingCondition based
Wait style
The best wait follows the app state, not the clock.

Final Quiz

Question 1 of 30 correct

What is the best kind of wait?