Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
Python interview question
Parallelism & flaky testsMiddleCommonDesign

What is a Playwright `BrowserContext`, and why is it central to test isolation and parallel execution?

Answer

A BrowserContext is an isolated browser session inside one browser process, similar to a fresh incognito profile: cookies, local storage, permissions and other session state are separated from other contexts. Creating a fresh context per test gives strong isolation without launching a full browser each time, while multiple pages in one context intentionally share session state. Use separate contexts for independent users or tests and reuse authentication through explicit storage-state setup rather than leaking state from one test into another.

Strong answer includes

  • describes BrowserContext as isolated browser-session state rather than another page
  • connects fresh contexts to cheap test isolation and safe parallelism
  • uses separate contexts for independent users and explicit storage state for controlled auth reuse

Practical example

A messaging test needs Alice and Bob online at once. It creates two contexts, logs each user in separately and opens one page per context. Their cookies and local storage cannot overwrite each other, while both sessions still run efficiently inside the same browser process.

#playwright#browser-context#test-isolation#parallel-testing

Sources

Playwright for Python documentationMicrosoft Playwright · Authoritative Python behavior for locators, auto-waiting, browser contexts, network controls and test isolationPlaywright Interview Questions for SDET 2026AI Test Automation Hub · 2026 interview signal for Playwright auto-waiting, semantic locators, browser contexts, network interception and debuggingPlaywright Interview Questions and Answers (2026 Guide)The Testing Academy · 2026 recurrence signal for Playwright locators, auto-waiting, fixtures, network interception and hands-on debugging