TOPIC 16/6020 MINNOT STARTED

Isolation: browser contexts and a fresh state for every test

Playwright gives each test a fresh browser context. Learn what that isolates, what it does not, and how to act as two users in one test.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a clean hotel room for each guest. No bags and no keys are left from the last guest. Guests cannot see each other's things. The hotel building, though, is still one building.

Daily List is a to-do list app. Tom's rename test passes alone. In the full run it fails. The browser room was clean. Both tests had used the same account on the server.

What it is: Playwright is a library that drives a real browser. This slice is isolation. Each test gets a fresh , a separate profile like a private window. A is one operating-system process that runs tests. Test data isolation is the matching rule for the server: each test gets its own rows. The nearest neighbour is a shared browser profile, which is how a careless Selenium suite leaks cookies from test to test.

Why it matters: A test that passes alone and fails in the suite wastes a day. A fresh context stops one test's cookies from poisoning the next. It does not stop two tests from editing the same server row.

A hotel room is cleaned by staff. Playwright makes a new context quickly. The server data is still shared until the tests stop sharing it.

(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are made up.)

PLAIN WORDS · 3 in this section
rename
give a new name to
playwright
a free Microsoft tool that drives a browser for tests
selenium
A free tool that drives a web browser for checks.

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Giving each test a clean browser, and remembering that the server is shared.

  1. Fresh context
  2. Unique data
  3. Clean up
  4. Repeat to check
Clean room, shared building

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
A freshly cleaned roomA new browser context
The building around the roomsThe server and its data
A name tag no one else hasA unique task title
Two guests in two roomsA multi-context test

WHERE THIS PICTURE STOPS

  • A hotel has staff who clean rooms, but Playwright makes a context new in a blink.
  • A hotel is one building, but a server can have many kinds of shared data.
  • Guests do not share keys, but two pages in one context do share cookies.

HOOK

Clean room, shared building.

REMEMBER IT THIS WAY

A story beat: one picture-line that carries the order or the cause.

The rename test passed alone but failed in the full run, because both tests shared the same task title on the same server.

What each part of the trick stands for
In the trickWhat it stands for
Passed alonethe browser room was clean
Failed in the full runthe problem was outside the room

A unique title only helps if each test really uses its own.

TELL A FRIEND

A hotel gives each guest a clean room, but the building is shared. Playwright cleans the room, and the team must keep the building tidy.

OFTEN MIXED UP WITH Fixtures: shared setup without copy-paste. A fixture builds and cleans set-up for a test. Isolation says what a test may share with others.

Sources & standards — 4 sources
  1. Market practice

    Isolation (Playwright documentation) ↗ — Microsoft (Playwright) · Each test gets its own browser context, a clean-slate profile like an incognito one, fast to create and fully isolated; a new context shares no cookies or cache with others; close contexts before the browser (search excerpt, page not opened)

    Says Playwright gives each test its own browser context, a clean-slate environment like an incognito profile that is fast to create and fully isolated. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Recommends isolated tests that do not depend on each other (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  3. Market practice

    Using HyperText Transfer Protocol (HTTP) cookies (Mozilla developer docs) ↗ — Mozilla (developer documentation) · After sign-in the server sets a cookie with a session identifier and the browser sends it back with later requests (search excerpt, page not opened)

    Per the search excerpt, after sign-in the server sets a cookie holding a session identifier and the browser sends it back with later requests. Without an expiry a cookie is a session cookie. A cookie is removed by setting its expiry in the past. The page advises sending a new session cookie at sign-in to stop session fixation. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Market practice

    Authentication (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes a setup project that logs in once and saves browser state to a file under playwright/.auth, loading it as storageState in browser projects, adding the folder to .gitignore because the file can hold sensitive cookies, one file per role and a separate account per worker. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

PRACTISE AND KEEP

Sources for this topic — 4 sources
  1. Market practice

    Isolation (Playwright documentation) ↗ — Microsoft (Playwright) · Each test gets its own browser context, a clean-slate profile like an incognito one, fast to create and fully isolated; a new context shares no cookies or cache with others; close contexts before the browser (search excerpt, page not opened)

    Says Playwright gives each test its own browser context, a clean-slate environment like an incognito profile that is fast to create and fully isolated. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Recommends isolated tests that do not depend on each other (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  3. Market practice

    Using HyperText Transfer Protocol (HTTP) cookies (Mozilla developer docs) ↗ — Mozilla (developer documentation) · After sign-in the server sets a cookie with a session identifier and the browser sends it back with later requests (search excerpt, page not opened)

    Per the search excerpt, after sign-in the server sets a cookie holding a session identifier and the browser sends it back with later requests. Without an expiry a cookie is a session cookie. A cookie is removed by setting its expiry in the past. The page advises sending a new session cookie at sign-in to stop session fixation. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Market practice

    Authentication (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes a setup project that logs in once and saves browser state to a file under playwright/.auth, loading it as storageState in browser projects, adding the folder to .gitignore because the file can hold sensitive cookies, one file per role and a separate account per worker. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.