๐ฅ Playwright: Browser, Context & Page - Real-time Demo and Multi-User Testing
.
๐ฏ Goal: Understand browser, context, and page in Playwright
๐ง 1. What is a browser?
✅ Definition:
A
browserin Playwright is a launched instance of a real browser (Chromium, Firefox, WebKit) that can be used for automated testing.
✅ Purpose:
-
It starts and controls the browser process.
-
It is the root of your test execution.
-
Required to create contexts and pages.
✅ Code Example:
๐ง 2. What is a context (browser context)?
✅ Definition:
A
contextis like a separate browser profile (or incognito tab) inside the browser. Each context is isolated — no cookies, local storage, or sessions are shared.
✅ Purpose:
-
Simulates multiple users or sessions.
-
Enables parallel and isolated testing.
-
Allows setting user-specific preferences (geo, locale, permissions).
✅ Code Example:
You can have multiple contexts in one browser instance.
๐ง 3. What is a page?
✅ Definition:
A
pageis a tab or window inside a context. It’s where all browser interactions happen — like navigating, clicking, typing, or making assertions.
✅ Purpose:
-
Used to interact with the web app under test.
-
Simulates a user's browser tab.
✅ Code Example:
๐ Full Flow Summary: browser ➝ context ➝ page
๐ก Real Example: Login Flow
๐งช Why Use context?
Let’s say you want to test multiple users in parallel:
Each context has its own storage — like two separate incognito windows!
✅ Key Takeaways
| Term | Description | Real-Life Analogy |
|---|---|---|
browser | Browser instance (e.g., Chromium) | Opening Chrome manually |
context | Separate, isolated browser profile/session | A new incognito window |
page | A tab or window to interact with the site | A single tab in the browser |
Comments
Post a Comment