Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
Playwright

Playwright Hand Book With Im Cseian | IMCSEIAN

Reviewed & accurate
AI Summary
Playwright Complete Course — Interactive Tutorial Series
Playwright Course
0% · 0/9

The Complete Playwright Course

Nine hands-on lessons that take you from zero to shipping E2E tests in CI — every step animated so you can see exactly what to do. 🎬

🎬 9 animated demos 🧠 9 quizzes 📋 Copy-ready code ⏱ ~35 min total

🚀 Start the course

Ready? Let's have fun! 🎉

Pick lesson 1 — your progress is saved automatically.

LESSON 1 · ~4 MIN · SETUP

Install & Setup Playwright

One command scaffolds everything — config, specs, GitHub Actions workflow, and all three browser engines. 👇

1

Scaffold the project

Run this in a new (or existing) project folder — it asks a few questions (TypeScript? GitHub Actions?) and installs Chromium, Firefox and WebKit:

bash
npm init playwright@latest
2

Meet the scaffold

These are the files that appear — you'll use every one of them in this course:

📁 tests/ → your spec files 📁 tests-examples/ → sample specs ⚙️ playwright.config.ts → configuration 🐙 .github/workflows/ → CI (optional)
🎬 Live: installing Playwright & the scaffold appearing DEMO
3

Run the example suite

The scaffold ships with sample tests — run them right away to verify your setup:

bash
npx playwright test

Tests run headless across all 3 browsers by default. Add --ui for the interactive UI Mode or --headed to watch.

🧠 QUIZ · LESSON 1

Which command scaffolds a Playwright project?

LESSON 2 · ~4 MIN · BASICS

Your First Playwright Test

test() → page fixture → page.goto(). Four steps to your first green checkmark — watch it happen live.

1

Create a spec file

In tests/, create a file with a .spec.ts (or .spec.js) extension:

📄 first-test.spec.ts📦 first-test.spec.js
2

Write the test

test() is one test case. The { page } argument is a built-in fixture that gives you an isolated browser page — no setup needed:

tests/first-test.spec.ts
import { test, expect } from '@playwright/test';

test('visits the site', async ({ page }) => {
  await page.goto('https://qa.imcseian.com/');
});
3

Run it!

From your project root:

bash
npx playwright test

Useful flags: --ui (UI Mode), --headed (watch the browser), --debug (inspector), first-test.spec.ts (run one file).

🎬 Live: writing the test & page.goto() opening the page DEMO
🧠 QUIZ · LESSON 2

What does page.goto() do?

LESSON 3 · ~4 MIN · BASICS

Locators — Find Elements

Playwright's superpower: user-facing locators that are readable, resilient, and auto-waiting.

1

The locator pyramid

Pick the most user-facing locator that works — they survive CSS refactors:

page.getByRole('button') page.getByLabel('Email') page.getByPlaceholder('Search') page.getByText('Welcome') page.getByTestId('submit') page.locator('.css-fallback')

getByRole is the top pick — it matches how users & screen readers see your app.

2

Chain & filter

Locators can be chained to narrow down, and reused many times:

login.spec.ts
const form = page.getByRole('form')
await form.getByLabel('Email').fill('qa@tester.io')
await form.getByRole('button', { name: 'Log in' }).click()
🎬 Live: locators finding & highlighting real elements DEMO
🧠 QUIZ · LESSON 3

Which locator does Playwright recommend first for buttons & links?

LESSON 4 · ~4 MIN · BASICS

Actions — Interact

Type, click, check, press — every action first waits for the element to be visible, stable and enabled.

1

The action toolbox

.fill('text') — inputs .click() — buttons .check() — checkboxes/radios .selectOption('x') — dropdowns .press('Enter') — keyboard .hover() — mouse over
2

A real flow — TodoMVC

Every Playwright demo starts here — adding & completing a todo:

todo.spec.ts
await page.getByPlaceholder('New todo').fill('Ship v2')
await page.keyboard.press('Enter')
await page.getByRole('checkbox').check()
await expect(page.getByText('1 item left')).toBeVisible()
🎬 Live: fill → Enter → check → assert DEMO
🧠 QUIZ · LESSON 4

Which method fills an input field?

LESSON 5 · ~3 MIN · BASICS

Assertions with expect()

Prove your app behaves. Web-first assertions that retry automatically until they pass.

1

expect(locator).to…

Import expect from Playwright — assertions take a locator, not a stale element:

first-test.spec.ts
await expect(page.locator('.title')).toBeVisible()
await expect(page.locator('.title')).toHaveText('Welcome')
await expect(page).toHaveURL(/dashboard/)
toBeVisibletoHaveTexttoContainText toHaveCounttoBeEnabledtoHaveURL
🎬 Live: assertions hitting the element & passing DEMO
🧠 QUIZ · LESSON 5

Which assertion checks exact text?

LESSON 6 · ~3 MIN · CORE CONCEPT

Auto-Waiting & Retries

The reason Playwright tests are not flaky: actions wait for actionability, and expect() retries.

1

How it works

Before acting, Playwright checks the element is visible, stable, enabled and receives events. And expect() keeps retrying (5s by default) until the assertion passes. No waitForTimeout(5000) hacks — that's an anti-pattern!

2

Custom timeout

Slow-loading element? Extend the timeout per assertion:

status.spec.ts
await expect(page.locator('.status'))
  .toHaveText('Success', { timeout: 10_000 })
🎬 Live: the retry loop — fail, retry, retry… pass! DEMO
🧠 QUIZ · LESSON 6

The element isn't there yet. What does expect() do?

LESSON 7 · ~4 MIN · DRY CODE

Fixtures & Hooks

Set up state once with hooks, drive tests with data, and even build your own fixtures.

1

Hooks — beforeEach & friends

Run setup before every test in a file — you get a fresh page fixture per test, so tests never leak state:

login.spec.ts
test.beforeEach(async ({ page }) => {
  await page.goto('/login')
})
2

Data-driven tests

Loop over a data array (or load a JSON file) and generate a test per record:

users.spec.ts
for (const u of users) {
  test(`login ${u.email}`, async ({ page }) => {
    await page.getByLabel('Email').fill(u.email)
  })
}

Built-in fixtures: page, context, browser, request. Create your own with test.extend() — e.g. an authenticated authedPage.

🎬 Live: data records flowing into generated tests DEMO
🧠 QUIZ · LESSON 7

When does test.beforeEach run?

LESSON 8 · ~5 MIN · PRODUCTIVITY

Codegen & Trace Viewer

Let Playwright write your tests, and debug failures with time-travel traces.

1

Record tests with codegen

Click and type in a real browser — Playwright writes the locators and code for you:

bash
npx playwright codegen https://qa.imcseian.com
🎬 Live: your clicks becoming code DEMO
2

Debug with traces

Turn on traces and every failing test gets a time-travel recording — DOM snapshots, network, console for every action:

playwright.config.ts
export default defineConfig({
  use: { trace: 'on-first-retry' },
})

Open results with npx playwright show-report or npx playwright show-trace — you can scrub through every step like a video.

🧠 QUIZ · LESSON 8

Which command records your actions as code?

LESSON 9 · ~4 MIN · SHIP IT

Run Playwright in CI/CD

Tests are only useful if they run on every push. Headless mode + GitHub Actions = automated confidence.

1

Headless by default

npx playwright test is already headless — perfect for CI. Use --headed / --ui only while developing:

bash
npx playwright test   # headless, all 3 browsers
2

GitHub Actions workflow

Create .github/workflows/playwright.yml:

.github/workflows/playwright.yml
name: E2E Tests
on: [push]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx playwright install --with-deps
      - run: npx playwright test

Enable retries on CI with retries: process.env.CI ? 2 : 0 — failed runs upload the HTML report + traces so you can see exactly why.

🎬 Live: the CI pipeline running your tests DEMO
🧠 QUIZ · LESSON 9

Which command runs tests headless by default?

🎓 Course complete — let's have fun! 🎉

You can now write, record, debug, and ship Playwright tests like a pro.

Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments