Testing / Playwright Interview questions
Explain the lifecycle of a browser context in Playwright?
A BrowserContext moves through a clear creation-to-disposal lifecycle, and understanding it explains why contexts are the natural unit of test isolation.
flowchart LR
A[browser.newContext] --> B[Context created: empty cookies/storage]
B --> C[context.newPage - one or more pages]
C --> D[Pages navigate, interact, share cookies/storage]
D --> E[context.close]
E --> F[All pages closed, storage discarded]
Creating a context from an already-launched browser is cheap because it doesn't start a new OS process - it just allocates a new, isolated storage partition within the existing browser. Every page opened from that context (including popups) shares its cookies, local storage, and permissions, which is why logging in on one page makes an authenticated request from a second page in the same context succeed too. Closing the context tears down every page it owns and discards all of that state, unless it was explicitly exported first via storageState().
More Related questions...