Q1.Explain the relationship between Browser, BrowserContext and Page in Playwright.
Almost every isolation, speed and auth question later in the interview depends on whether you understand this three-level model.
A Browser is one launched browser process. A BrowserContext is an isolated profile inside that process — its own cookie jar, local/session storage, permissions, geolocation and cache. A Page is a single tab inside a context.
The practical consequence: creating a context is cheap (a few milliseconds) while launching a browser is expensive (hundreds of milliseconds). That is why Playwright Test gives every test a fresh context but reuses the browser process across tests in the same worker — you get incognito-grade isolation without paying for a new browser each time.
const browser = await chromium.launch();
const context = await browser.newContext({ locale: 'en-GB' });
const page = await context.newPage();- Saying a context is 'just a tab' — a context can hold many pages.
- Assuming logging in on one page logs you in across contexts; storage is per-context.