Testing / Playwright Interview questions
What is the purpose of browser contexts in Playwright?
A BrowserContext is an isolated browser session - its own cookies, local storage, cache, and permissions - created from a single launched Browser instance without the overhead of starting a whole new browser process.
const browser = await chromium.launch(); const context = await browser.newContext(); const page = await context.newPage();
Because contexts are cheap to create and fully isolated from each other, Playwright Test spins up a fresh context per test by default, which prevents state leaking between tests (like a stale login session) without paying the cost of relaunching the browser executable every time. Multiple contexts can also run in parallel from one browser instance, which is a major reason Playwright test suites are fast.
More Related questions...