AdvancedPW-DBG-00140 minutesPlaywright

Debug a hidden race condition

A provided test reads delayed text immediately and fails intermittently.

  • debugging
  • trace-viewer
  • waits

Objective

What to automate

Run the failing test with trace, diagnose the race, and replace the eager read with a web-first assertion.

Preconditions and test data

Preconditions

  • Use a fresh isolated Practice Lab browser context.
  • Open the fixture identified by FX-WAIT-001.

Test data

  • starter: examples/debugging/hidden-race.spec.ts

Expected result

The trace proves the assertion ran before the delayed update; the repaired test waits on the final text.

Progressive hints

Hint 1

Open the action timeline in Trace Viewer.

Hint 2

Compare the assertion timestamp with the DOM snapshot.

Hint 3

Use expect(locator).toHaveText instead of reading textContent immediately.

I’ve tried it — show solution
  1. Open the action timeline in Trace Viewer.
  2. Compare the assertion timestamp with the DOM snapshot.
  3. Use expect(locator).toHaveText instead of reading textContent immediately.

The deliberately failing starter is in examples/debugging/hidden-race.spec.ts inside the TypeScript starter ZIP.