Chapter 34: First Playwright test
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
First Playwright test
A test has a readable name and an asynchronous body. The page fixture is an isolated page provided by Playwright Test. Arrange the state, perform an action and assert an observable outcome. setContent makes a small reproducible example without an external website.
How it works
Step-by-step walkthrough
- Create tests/first.spec.ts
- Paste the example
- Run npx playwright test tests/first.spec.ts
Example
import { test, expect } from '@playwright/test';
test('button is visible', async ({ page }) => {
await page.setContent('<button>Start</button>');
await expect(page.getByRole('button', { name: 'Start' })).toBeVisible();
});Use descriptive names that explain the expected behavior.
✎ Your practice task
Change Start to Stop only in the assertion.
Knowledge check
Which fixture gives you a browser page?
🌐 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.