In this lesson you go from an empty folder to a Playwright project in TypeScript: you create it with one command, read the sample test, run it on three browsers, and open the HTML report. Everything follows the official Installation guide, and every command and output below comes from a real run.
What you need
- Node.js. When this lesson was recorded, the Installation page listed versions 22, 24 and 26.
- A code editor, for example Visual Studio Code.
- An empty folder for the new project.
The code of this lesson was recorded with Playwright 1.65.1; other versions may print slightly different output.
Why automate at all
Checking by hand and checking with Playwright differ in three ways:
| By hand | Playwright | |
|---|---|---|
| Repeating | Every check starts from scratch | Re-run with one command |
| Browsers | Open them one by one | Chromium, Firefox and WebKit in one run |
| Results | Remembered or screenshotted | An HTML report with every step |
Step 1: Create the project
Open a terminal in the empty folder and run the init command from the docs:
npm init playwright@latest
It asks four questions:
- Do you want to use TypeScript or JavaScript? Choose TypeScript, which is also the default.
- Where to put your end-to-end tests? Keep the name
tests. - Add a GitHub Actions workflow? Say no for now. We come back to it in the CI lesson.
- Install Playwright browsers? Say yes. Playwright downloads Chromium, Firefox and WebKit.
The rest of the output, abridged:
Getting started with writing end-to-end tests with Playwright:
Initializing project in '.'
Initializing NPM project (npm init -y)…
Installing Playwright Test (npm install --save-dev @playwright/test)…
Installing Types (npm install --save-dev @types/node)…
Writing playwright.config.ts.
Writing tests/example.spec.ts.
Writing package.json.
Downloading browsers (npx playwright install)…
✔ Success! Created a Playwright Test project at ~/my-project
What was created
my-project/
tests/
example.spec.ts
.gitignore
package.json
package-lock.json
playwright.config.ts
tests/example.spec.tsis a sample test you can run right away.playwright.config.tsis where browsers, reports and retries are configured.package.jsonrecords that Playwright is installed, as adevDependency..gitignorekeepsnode_modules, test results and the report out of git.
Step 2: Read the config
Three lines of playwright.config.ts are worth knowing right away. Here is the file trimmed down (the generated one has more comments and options):
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
reporter: 'html',
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } },
],
});
testDirtells Playwright where to find tests.projectslists the browsers to run, three by default.reporteris how results are reported, an HTML report by default.
Step 3: Read the sample test
import { test, expect } from '@playwright/test';
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
});
test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');
// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();
// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});
- The file starts by importing
testandexpectfrom the Playwright library. - The first test,
has title, receivespage: a browser page.gotoopens the playwright.dev home page, thenexpectchecks that the title contains "Playwright". - The second test clicks the Get started link and checks that the Installation heading appears.
Waiting for the page
One notable difference is how Playwright waits. The old style uses a fixed wait, for example three seconds, before checking:
// The old way: a fixed wait. Shown only for comparison.
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.waitForTimeout(3000);
expect(await page.title()).toContain('Playwright');
});
With Playwright, expect waits until the condition is true or time runs out. So the test is shorter and depends less on how fast the page loads.
Step 4: Run the tests
First, ask Playwright what it is going to run:
npx playwright test --list
Listing tests:
[chromium] › example.spec.ts:3:1 › has title
[chromium] › example.spec.ts:10:1 › get started link
[firefox] › example.spec.ts:3:1 › has title
[firefox] › example.spec.ts:10:1 › get started link
[webkit] › example.spec.ts:3:1 › has title
[webkit] › example.spec.ts:10:1 › get started link
Total: 6 tests in 1 file
Six tests from one file: two tests times three projects. Now run them:
npx playwright test
Running 6 tests using 2 workers
[1/6] [chromium] › tests/example.spec.ts:10:1 › get started link
[2/6] [chromium] › tests/example.spec.ts:3:1 › has title
[3/6] [firefox] › tests/example.spec.ts:3:1 › has title
[4/6] [firefox] › tests/example.spec.ts:10:1 › get started link
[5/6] [webkit] › tests/example.spec.ts:3:1 › has title
[6/6] [webkit] › tests/example.spec.ts:10:1 › get started link
6 passed (8.7s)
By default, tests run in parallel and headless: no browser window is shown.
Why six tests? Playwright reads the config, then finds two tests in the tests folder. Each test runs on all three browsers listed in projects. Two times three is six, split across two workers running in parallel. All six pass, and the results are collected into the HTML report.
| Tests | Browsers | Workers | Time |
|---|---|---|---|
| 6 (2 × 3) | 3 | 2 | 8.7 s |
Watch the browser work
To see the browser, add the --headed flag. Adding --project=chromium runs one browser only, and --workers=1 runs the tests one after another, which is easier to follow:
npx playwright test --headed --project=chromium --workers=1
Running 2 tests using 1 worker
[1/2] [chromium] › tests/example.spec.ts:3:1 › has title
[2/2] [chromium] › tests/example.spec.ts:10:1 › get started link
2 passed (5.4s)
You see the page open, click Get started, and check the heading, just like a real user.
Step 5: Open the HTML report
npx playwright show-report
Serving HTML report at http://localhost:9323. Press Ctrl+C to quit.
At the top are filters for browser, passed, failed, flaky and skipped tests. Click a test to see its steps, errors and attachments. The report lives in the playwright-report folder.
One thing to remember: the report opens by itself only when a test fails. Otherwise, open it by hand with this command.
What else is in Playwright
Playwright is more than a library that runs tests. The toolkit has five groups, and the next lessons cover them:
- Writing tests: Codegen records your actions; the VS Code extension; fixtures.
- Running: the command line, UI Mode, and parallel workers.
- Finding failures: Trace Viewer, Inspector and debug mode.
- Reporting: the HTML report, or JUnit for CI systems.
- AI: Playwright MCP and test agents.
Check yourself
Which command opens the HTML report?
npx playwright show-reportnpx playwright reportnpx playwright opennpx playwright html
The answer is the first one: the report lives in the playwright-report folder, and show-report opens it in the browser.
Recap
- Create the project with one command:
npm init playwright@latest, TypeScript and atestsfolder. - Read the sample test to understand
page,gotoandexpect. - Run the tests: six pass on three browsers. Add
--headedto watch. - Open the HTML report with
npx playwright show-report.
Next lesson
Next, we write our own tests: actions and assertions.