lecture 16 of 200 completed

Browser contexts and why your tests do not leak into each other

The idea behind Playwright's isolation. It explains why tests start logged out, and it is a common interview question.

What you'll learn

  • What a browser context is, and why tests cannot leak into each other
  • Why every test starts logged out
  • How two contexts let one test act as two users

Here is a question worth being able to answer, because interviewers ask it: why do Playwright tests not interfere with each other, even running in parallel?

The answer is the browser context, and understanding it explains several behaviours that otherwise look arbitrary.

Three layers, from big to small.

The browser is the running browser process. Starting one is slow, so Playwright starts few of them.

A context is an isolated session inside that browser. Its own cookies, its own localStorage, its own cache. Think of it as a fresh incognito window. Creating one is fast, a few milliseconds.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →