Objective: Debug a failing test from its evidence stack instead of re-running and hoping, and classify every intermittent failure by species — timing, state, order, environment, product, or test-design — because each species has a different cure.
⏱ ≈2 h practice unit · Code: copy, paste, practise · English edition — Español · العربية · বাংলা in translation
🧽 The practice business: FreshNest Home Cleaning — a fictional local cleaning company (owner: Maya Torres) invented for this course. Every example and exercise uses FreshNest, so you learn on a complete, realistic business without ever touching a real one.
Two skills separate senior automation engineers: reading evidence instead of re-running and hoping, and flake discipline — treating intermittent failure as a diagnosis problem, never as a retry-settings problem. Playwright's evidence stack has a professional opening order. First the trace: a time-travel recording with every action, the DOM at that moment, network, and console — you do not guess what the page looked like, you visit it. Then the video, the human-speed story, which catches animations and flicker that traces make tedious. Then the failure screenshot, one frame at a glance. Then the error's own text, read fully: assertion errors carry expected-versus-actual, locator errors carry what was searched and what the page contained — the answer is embarrassingly often in line three.
Waits are the root of half of all flake. Playwright auto-waits: actions and assertions retry until the element is actionable or the expectation holds, up to the expect timeout. Flake is born when tests fight that system — chiefly waitForTimeout used as a strategy. A fixed sleep is a bet that the machine is always faster than your number and never slower. Replace sleeps with the assertion that describes "ready": expect the spinner to vanish, the text to appear, the count to change. Two cousins cause the rest: asserting too early on derived state (the element exists but its data has not landed — assert the data, the total or the count, not the container), and animation or re-render churn, where an element is found then replaced mid-click — cured by a better anchor that lets auto-wait ride out the churn, not by a longer sleep.
Name the species before you fix it. Timing flake passes locally and fails under CI load; its cure is real readiness assertions. State flake fails with others and passes alone; cure is independence — own data, own account, real teardown. Order flake fails after one specific test; hunt the shared-state leak. Environment flake lives in one browser or device column only; fix the locator or assumption, or accept and document the engine difference. Product flake means the application is intermittently broken — the test is right, so file it with the trace attached and do not shoot the messenger. Test-design flake fails when data changes legitimately, from over-specified assertions. Retries are diagnostics, not cures: in gating runs, count retry-passes as failures in reporting, or the flake rate goes invisible exactly where it matters. P-04 prices why: the flake tax is the triage time, the rerun and blocked-pipeline cost, plus the trust term — unmeasurable and dominant, because a suite whose signal is doubted trains a team to ship through alarms. Govern it like an operation: a flake ledger, suite-health expectations with owners and breach actions agreed before the breach, quarantine with an owner and an expiry, and governed deletion recorded as a decision.