Browser Context
// Definition
An isolated browser session with its own cookies, storage, and cache — like a fresh incognito window, but programmatic. Playwright's `browser.newContext()` creates one; each is fully independent. Contexts let one test run exercise multiple users simultaneously (e.g. a chat between user A and user B) without cross-contamination.
// Why it matters
Browser contexts are how QA tests multi-user and isolation scenarios cleanly — two logged-in users in one test, or guaranteeing no leftover session bleeds between tests. They're faster than launching whole browsers and are the modern answer to test independence at the session level. Cypress handles this differently (per-test clearing); Playwright makes contexts explicit.
// How to test
// Playwright: two isolated users in one test (e.g. real-time chat)
const userA = await browser.newContext()
const userB = await browser.newContext()
const pageA = await userA.newPage()
const pageB = await userB.newPage()
await pageA.goto('/chat'); await pageB.goto('/chat')
// A sends, B receives — fully isolated sessions, no cookie bleed// Common mistakes
- Reusing one context across tests so session state leaks between them
- Spinning up whole browsers when a new context would be faster and lighter
- Assuming Cypress and Playwright isolate sessions identically (they differ)
// Related terms
Headless Browser
A real browser running without a visible UI. Used in CI for speed and reproducibility — same rendering engine as a normal browser, with no display required.
Session
A server-side or client-side record that persists a user's authenticated state across requests. Sessions are created on login, referenced by a session ID sent in a cookie or header, and invalidated on logout or expiry. Testing considerations include: session fixation (attacker sets the victim's session ID before login), failure to rotate the ID after privilege escalation, excessively long session lifetimes that extend exposure after credential compromise, and whether logout actually invalidates the server-side session.
Test Independence
Each test sets up its own state and doesn't depend on others — order can change, parallelisation works, a single failure doesn't cascade. The non-negotiable property for a maintainable test suite.