Chapter 31: Playwright introduction and architecture
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Playwright introduction and architecture
Playwright automates web browsers for end-to-end testing. Playwright Test adds a runner, assertions, fixtures and reporting. An end-to-end test exercises a user journey and checks the observable result, such as a successful sign-in. Playwright sends commands to browser engines through its automation implementation. A browser process can contain isolated browser contexts, and each context can have pages. Chromium, Firefox and WebKit projects help check compatibility; WebKit is not identical to every Safari environment.
How it works
Step-by-step walkthrough
- Identify a user journey
- Describe actions
- Define the expected outcome
Example
This is a focused snippet. Use it in the file or test context described in the walkthrough.
// tests/first.spec.ts
import { test, expect } from '@playwright/test';
test('smoke check', async ({ page }) => {
await page.setContent('<h1>Welcome</h1>');
await expect(page.getByRole('heading')).toHaveText('Welcome');
});Browser, context and page example
Run as a TypeScript script using a compatible TypeScript execution setup, or adapt it into a test.
import { chromium } from '@playwright/test';
async function run() {
const browser = await chromium.launch();
try {
const context = await browser.newContext();
const page = await context.newPage();
await page.setContent('<h1>Lab</h1>');
console.log(await page.locator('h1').textContent());
} finally { await browser.close(); }
}
run().catch(console.error);Test the user-visible behavior, not internal implementation details. Prefer runner-provided fixtures for ordinary tests.
✎ Your practice task
Change the expected heading to see a failure.
Knowledge check
What makes an automated check a test?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.