Objective: Design journeys that begin from a declared state — seeded through the fastest honest door, by test accounts only — and guarantee teardown, then govern data and environments so results always name the row they came from.
⏱ ≈2.5 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.
Basic journeys start at the home page as a stranger. Real journeys start mid-story: "as a logged-in customer with two items in the cart…" That precondition is state, and managing it is the difference between journey tests that scale and a pile of scripts that each spend twenty steps re-doing login. The professional tool is the fixture: a named, reusable setup that a test declares instead of performs. Playwright's built-ins — page and request, in your hands since LAB-1 — are fixtures; custom fixtures extend the same idea to your world. Three rules keep fixtures safe. Setup goes through the fastest honest door: seeding state via the product's API beats clicking through five screens — unless the clicking is what the test is about. Login as setup → API; login as the subject of the test → the UI. Fixtures authenticate with dedicated test accounts on staging, always — never real accounts, never live purchases; a fixture that logs in as a real customer is an incident with a schedule. And cleanup is part of the fixture, not a hope: whatever setup created, teardown removes, in a finally-style guarantee that runs even when the test fails halfway — because tests that pollute shared state make the next tests liars, and test independence is manufactured here.
State has a taxonomy, and a journey's state contract names all four kinds: identity (a logged-in test user — created by fixture login, API-first, on staging), data (products, listings, prices — seeded via API or fixtures, versioned with the suite), progress (a half-filled form, a saved draft — driven through the UI, because this state IS UI behaviour), and environment (feature flags, locale — set at config or project level, never as mid-test surprises). Writing the contract — each kind, the door you'd create it through, the teardown that removes it — is most of the implementation. And when a stateful journey fails, triage splits three ways: the story broke, the state was wrong (the fixture seeded stale data — the failure is in setup, not the product), or a previous test's cleanup didn't happen (independence violated). The trace shows which: if the first frame already looks wrong, suspect state before product — first-frame forensics, before filing anything against the app.
At enterprise scale (P-05) the same principles harden into governance. Production data is not test data: copying real customer data into test environments is a privacy and security exposure and usually a compliance violation; the lawful patterns are masking (structure preserved, identities irreversibly scrambled) and synthetic data — LAB-3's factories grown up, with realistic distributions and zero real people. Environments are definitions, not places: an environment definition — config, flags, seeded reference data, dependency versions — is reviewed and changed like code, because "staging" that drifts from production produces the classic disease: green there, broken here. The environment table makes the pattern explicit — dev/local (synthetic, disposable, anyone may break it), CI ephemeral (created per run, destroyed after), staging (masked or synthetic, test accounts only, announced windows), production (real, read-only, the never-submit rule absolute). As realism rises, permission to disturb falls; most "environment issues" are row confusion — running staging-style experiments under production rules. Name your row before any run, and report which row — and which provider mode — every result came from: a payment sandbox behaves only approximately like the real provider, so greenness against a sandbox certifies the contract, never the provider.
The original worked code for this unit, verbatim, with its line-by-line explanations. Run it against the course practice project (download on the course page).
// Pattern (illustrative, built on the real Page Objects from B-05):
// a "loggedInPage" fixture logs in ONCE, as a TEST account, before the
// test body runs — the test starts already inside the story.
test("checkout journey", async ({ loggedInPage }) => {
const home = new HomePage(loggedInPage);
// …the story begins here, state already true…
});From the module's full text.