Architecture
Page in Playwright
A Playwright page represents one browser tab where tests navigate, locate elements, perform actions, listen to events, and assert UI state.
Definition and Brief Explanation
Definition: A page is the Playwright object that represents one browser tab.
Explanation: The page object is the main surface used in UI tests. It opens URLs, creates locators, performs actions, listens for browser events, and connects test code to what the user sees in the tab.
Lifecycle
- Open a page from a browser context.
- Navigate with page.goto() or user actions.
- Create locators from the page.
- Listen for dialogs, downloads, popups, or responses.
- Assert the final page state.
Example
Use page fixture
test('search works', async ({ page }) => {
await page.goto('/');
await page.getByRole('searchbox').fill('Playwright');
});
Explanation: The page fixture gives the test a ready browser tab.
Common Confusion
- page should not be treated as a global object shared by all tests.
- Prefer user-facing locators from page.
- Wait for page state, not fixed time.