QA Knowledge Base

Playwright
Reference
Hub

Total Hours 20 hrs
Sessions 20 × 60 min
Review 15 min each
Pace Self-directed
Principle 80/20 Focus
⚡
The 80/20 approach: Most Playwright work — writing locators, handling async flows, assertions, page fixtures, and CI integration — is covered by about 20% of the API. This plan front-loads exactly that core. By session 10 you'll be productive on real projects. Sessions 11–20 add the professional layer that separates a tester from a test engineer.
Quick Access
Jump to the patterns and topics used most often
Common Tasks
Find What You Need
Search by keyword or filter by topic
Your Progress
0 of 20 sessions complete 0 / 20 hours
Phase 1
Foundations & Core Concepts
Locator Patterns
/* Best Practice Hierarchy */
getByRole('button', { name: 'Submit' })
getByLabel('Email')
getByText('Confirm Order')

/* Fallback */
locator('[data-testid="submit-btn"]')

/* Avoid when possible */
locator('.btn.primary')
locator('//div[3]/button[2]')
Date / Time Handling
/* Add 3 days */
const future = new Date();
future.setDate(future.getDate() + 3);

/* Round to nearest 15 minutes */
let minutes = future.getMinutes();
let rounded = Math.round(minutes / 15) * 15;

if (rounded === 60) {
  rounded = 0;
  future.setHours(future.getHours() + 1);
}

/* Handle midnight rollover */
if (future.getHours() === 0 && rounded === 0) {
  future.setDate(future.getDate() + 1);
}

/* Format (MM/DD/YYYY) */
const date = future.toLocaleDateString('en-US');

/* Format time */
const time = `${future.getHours()}:${String(rounded).padStart(2,'0')}`;
Wait / Stability Patterns
/* Wait for element */
await expect(locator).toBeVisible();

/* Wait for loading spinner to disappear */
await expect(loadBox).not.toBeVisible();

/* Wait for navigation */
await page.waitForURL('**/orders');

/* Wait for API response */
await page.waitForResponse(resp =>
  resp.url().includes('/api/orders') && resp.status() === 200
);

/* Avoid this */
await page.waitForTimeout(2000); // ❌ flaky
01
Environment Setup & First Test
Core Setup Node.js
▾
Install Playwright, scaffold a project, and run your first passing test against a live URL. Understand the project structure and config file.
  • Node.js + npm prerequisites check
  • npm init playwright@latest — what it creates and why
  • playwright.config.ts anatomy: baseURL, browsers, timeout
  • Writing a minimal test with test(), page.goto(), expect()
  • Running tests: npx playwright test, --ui flag, --headed
  • Reading the HTML report: npx playwright show-report
Docs
Playwright — Installation Guide
playwright.dev/docs/intro — official getting started, always current
Video
Playwright Full Course – Learnwebcode (YouTube)
Watch chapters 1–2 only (~25 min). Clear walkthrough for first-timers.
Practice
playwright.dev/docs/writing-tests
Run all three examples in the quickstart yourself — don't just read
15-min Review Self-check questions
  • What does playwright.config.ts control, and which 3 settings matter most day-to-day?
  • What's the difference between --ui and --headed?
  • Write from memory: a 5-line test that visits example.com and checks the title.
02
Locators — The Core Skill
Core Selectors DOM
▾
Master the Locator API — the single most important concept in Playwright. Understand why locators beat raw selectors and how to write resilient ones.
  • Locator vs ElementHandle — always use Locator
  • Built-in role locators: getByRole(), getByText(), getByLabel(), getByPlaceholder(), getByTestId()
  • CSS and XPath as fallbacks — when and why
  • Chaining locators: page.locator('.card').getByRole('button')
  • The Playwright Inspector for picking locators live
  • Locator best-practice hierarchy (ARIA > text > test-id > CSS)
Docs
playwright.dev/docs/locators
Read the entire Locators page — this is the highest ROI page in all of the docs
Video
"Playwright Locators Deep Dive" — Automated Testing with Cypress/Playwright channel
Search YouTube for this title; ~20 min hands-on walkthrough of all built-in locators
Practice
practice.expandtesting.com or demoqa.com
Write 10 locators using only getByRole/getByLabel — no CSS allowed in this drill
15-min Review Self-check questions
  • When would you use getByTestId over getByRole?
  • What is auto-waiting and how does it relate to locators?
  • Name 3 signs that a locator will be brittle in production.
03
Actions & Auto-Waiting
Core Interactions Async
▾
Learn how Playwright auto-waits before every action, and how to use every major interaction method: click, fill, select, check, hover, keyboard, drag.
  • How auto-wait works: actionability checks (visible, stable, enabled)
  • click(), fill(), type(), press(), selectOption()
  • check() / uncheck() for checkboxes and radios
  • hover(), focus(), blur()
  • dragAndDrop() and mouse events
  • page.keyboard and page.mouse for low-level control
  • Uploading files with setInputFiles()
Docs
playwright.dev/docs/input & /docs/actionability
Read both pages back to back — actionability is what prevents flaky tests
Practice
formy.herokuapp.com
Automate the entire form: text fields, dropdowns, checkboxes, radio, file upload, date picker
15-min Review Self-check questions
  • What are the 4 actionability checks Playwright performs before clicking?
  • What's the difference between fill() and type()?
  • How would you upload multiple files at once?
04
Assertions with expect()
Core Assertions expect
▾
Write precise, auto-retrying assertions that form the backbone of every test. Know the full set of web-first matchers and when to use soft assertions.
  • Web-first matchers: toBeVisible(), toHaveText(), toHaveValue(), toBeEnabled(), toBeChecked()
  • URL and page matchers: toHaveURL(), toHaveTitle()
  • Count matchers: toHaveCount()
  • Attribute matchers: toHaveAttribute(), toHaveClass()
  • Soft assertions with expect.soft()
  • Negation with .not
  • Custom assertion timeout overrides
Docs
playwright.dev/docs/test-assertions
Bookmark this — you'll return to it constantly. Read every matcher once.
Practice
Write 15 targeted assertions
Use books.toscrape.com — assert title, prices, ratings, URLs using different matchers for each
15-min Review Self-check questions
  • Why do web-first assertions auto-retry, and what's the default retry window?
  • When should you use expect.soft() instead of a normal assertion?
  • What's the difference between toHaveText() and toContainText()?
05
Test Structure, Hooks & Fixtures
Core Architecture Fixtures
▾
Understand how to structure test files professionally using describe blocks, hooks, and Playwright's powerful fixture system for reusable setup/teardown.
  • test.describe() for grouping related tests
  • test.beforeEach(), test.afterEach(), test.beforeAll(), test.afterAll()
  • Built-in fixtures: page, context, browser, request
  • Creating custom fixtures with test.extend()
  • Fixture scope: test vs worker-scoped
  • test.use() for per-suite configuration overrides
Docs
playwright.dev/docs/test-fixtures
The fixtures page is dense but worth every minute — it's the foundation of scalable test suites
Video
"Playwright Fixtures Explained" — Testerops / Artem Bondar YouTube
~15 min. Best visual explanation of fixture scope and extend() pattern
15-min Review Self-check questions
  • What's the difference between a test-scoped and worker-scoped fixture?
  • When would you use beforeAll vs beforeEach?
  • Create a custom loggedInPage fixture from memory.
Phase 2
Real-World Patterns
06
Page Object Model (POM)
Pattern Architecture Maintainability
▾
Implement the Page Object Model — the industry-standard pattern for maintainable test suites. Build a real POM layer for a multi-page app.
  • Why POM: encapsulation, DRY, readable tests
  • TypeScript class structure for a Page Object
  • Constructors receiving Page instance
  • Exposing actions as methods, locators as getters
  • Composing page objects across navigation flows
  • POM + custom fixtures: the professional combo
  • Component Objects for reusable UI fragments
Docs
playwright.dev/docs/pom
Official POM guide with full example — read then immediately rewrite it from scratch
Repo
github.com/microsoft/playwright/tree/main/examples
Study the todomvc example — best real-world POM reference from the Playwright team itself
Practice
Build POM for saucedemo.com
Login page, Inventory page, Cart page, Checkout flow — 4 page objects, 8 tests
15-min Review Self-check questions
  • What goes in a Page Object vs what stays in the test file?
  • How do you integrate POM classes with Playwright fixtures?
  • What's the risk of putting assertions inside page objects?
07
Network Interception & Mocking
Pattern Network API
▾
Intercept, mock, modify, and spy on network requests. This skill lets you test UI states that are hard to reproduce with a real backend.
  • page.route() to intercept and fulfill requests
  • Returning mock JSON responses with route.fulfill()
  • Modifying requests in flight with route.continue()
  • Aborting requests with route.abort()
  • Waiting for network events: page.waitForResponse()
  • HAR recording and replay for snapshot testing
  • API testing with request fixture (no browser needed)
Docs
playwright.dev/docs/network & /docs/mock
Both pages — network and mock are complementary, read them together
Practice
Mock a REST API on jsonplaceholder.typicode.com
Intercept GET /posts, return 3 custom items, assert UI renders them correctly
15-min Review Self-check questions
  • What's the difference between route.fulfill() and route.continue()?
  • When would you use HAR recording instead of manual mocking?
  • How do you test an empty-state UI when the API normally returns data?
08
Authentication Strategies
Pattern Auth Performance
▾
Implement fast, reliable authentication in your test suite. Learn to reuse auth state across tests to eliminate slow repeated logins.
  • Storage state: saving and loading cookies + localStorage
  • page.context().storageState() for saving session
  • Global setup file pattern for one-time login
  • storageState in playwright.config.ts
  • Multiple user roles with multiple storage state files
  • API-based login (faster than UI login) for auth setup
  • Handling JWT tokens and session refresh
Docs
playwright.dev/docs/auth
Full authentication strategies page — the "Reuse signed-in state" section is the key concept
Guide
"Playwright Authentication" — Testerops blog
Search for this post — excellent comparison of all auth approaches with benchmarks
15-min Review Self-check questions
  • Why is API-based login faster than UI login for test setup?
  • How do you handle tests that need to run as two different user roles?
  • What gets saved in a storageState file — cookies only or more?
09
Waiting, Timeouts & Flake Prevention
Pattern Reliability Debugging
▾
Understand Playwright's timeout hierarchy and write tests that never use waitForTimeout(). Learn to diagnose and fix flaky tests systematically.
  • Timeout hierarchy: global → test → action → expect
  • page.waitForURL(), page.waitForLoadState()
  • locator.waitFor() for explicit element waiting
  • page.waitForFunction() for custom conditions
  • Why waitForTimeout() causes flakes — and alternatives
  • Retries with test.retries — when appropriate
  • Using --trace on to debug flakes
Docs
playwright.dev/docs/timeouts & /docs/navigations
Navigation + timeout docs together explain 90% of timing issues
Guide
"Fixing Flaky Playwright Tests" — Playwright blog / GitHub blog
Search for this article on playwright.dev/blog — first-party anti-flake strategies
15-min Review Self-check questions
  • Name all 4 levels of the Playwright timeout hierarchy.
  • A test passes locally but fails in CI 30% of the time. What's your diagnostic process?
  • What's the correct alternative to await page.waitForTimeout(2000)?
10
Debugging Tools & Trace Viewer
Tooling Debug Trace
▾
Become fluent with Playwright's debugging toolkit. After this session, a failing test is a puzzle you can always solve — not a mystery.
  • Playwright Inspector: PWDEBUG=1 — step through tests live
  • Trace Viewer: recording, opening, and reading a trace
  • Screenshots on failure: screenshot: 'only-on-failure'
  • Video recording configuration
  • page.pause() for breakpoint-style debugging
  • UI Mode (--ui): live reload and trace viewer built in
  • VS Code Playwright extension — run, debug, pick locators
Docs
playwright.dev/docs/debug & /docs/trace-viewer
Both are short — read then spend remaining time with hands-on trace recording
Video
"Playwright Trace Viewer" — official Playwright YouTube channel
~10 min demo of the trace viewer — fastest way to see what's possible
15-min Review Milestone check — you're halfway!
  • Walk through the trace viewer: what 5 types of info can you see in a trace?
  • What's the fastest way to pick a locator for an element you've never seen before?
  • At this point you should be able to: write tests, use locators, assert, structure with POM, handle auth, mock APIs, and debug failures. What's the weakest of these for you?
Phase 3
Advanced Capabilities
11
Visual Regression Testing
Advanced Screenshots Visual
▾
Add screenshot comparison to your test suite to catch visual regressions. Understand thresholds, masking, and managing snapshot updates across platforms.
  • expect(page).toHaveScreenshot() — full page snapshots
  • expect(locator).toHaveScreenshot() — component-level
  • Snapshot update workflow: --update-snapshots
  • Threshold and pixel diff options
  • Masking dynamic content with mask option
  • Cross-platform snapshot challenges (OS-specific rendering)
  • Integrating with Percy or Argos for cloud-based diffs
Docs
playwright.dev/docs/test-snapshots
Short, focused page — read fully, then implement on a real UI component
15-min Review Self-check questions
  • How do you handle elements with dynamic content (timestamps, ads) in visual tests?
  • What are the tradeoffs of storing snapshots in git vs a cloud service?
  • When would visual testing add more value than assertion-based testing?
12
API Testing with Playwright
Advanced API REST
▾
Use Playwright's APIRequestContext to test REST APIs directly — no browser needed. Combine API + UI tests for full integration testing.
  • request fixture for API-only tests
  • GET, POST, PUT, DELETE with request.get/post/put/delete()
  • Setting headers, auth tokens, and base URL
  • Parsing JSON responses and asserting status codes
  • Using API calls to seed test data before UI tests
  • Using API calls to clean up after UI tests
  • playwright.request.newContext() for standalone API contexts
Docs
playwright.dev/docs/api-testing
Read fully. Then practice against reqres.in — a free hosted REST API for testing
15-min Review Self-check questions
  • What's the advantage of API-based test data setup over UI-based?
  • How do you share authentication state between API and browser contexts?
  • Write a test that creates a user via API, then verifies they appear in the UI.
13
Parallel Execution & Test Configuration
Advanced Performance Config
▾
Configure Playwright for fast parallel test runs. Understand workers, sharding, and projects — the trio that controls test execution speed.
  • Workers: fullyParallel, workers config options
  • Test isolation and state management with parallel tests
  • Projects: running the same suite across multiple browsers
  • Named projects for different environments (dev, staging, prod)
  • Sharding for CI: --shard=1/4 to split across machines
  • Test tagging and filtering: --grep, test.tag
  • Slow tests annotation and retry strategy per project
Docs
playwright.dev/docs/test-parallel & /docs/test-projects
Read both — they're short. Then configure a 3-project setup (chrome/firefox/webkit) locally
15-min Review Self-check questions
  • What makes two tests "safe" to run in parallel vs unsafe?
  • How does sharding differ from running with multiple workers?
  • When would you create separate Playwright projects for the same test suite?
14
Handling Complex UI Scenarios
Advanced iFrames Dialogs Tabs
▾
Handle the tricky UI scenarios that trip up most beginners: iframes, popups, new tabs, alert dialogs, file downloads, and shadow DOM.
  • iFrames: frameLocator() — the modern approach
  • Popups and new tabs: page.waitForEvent('popup')
  • Alert/confirm/prompt dialogs: page.on('dialog', ...)
  • File downloads: page.waitForEvent('download')
  • Shadow DOM: locator.shadowRoot() vs CSS piercing
  • Multi-page workflows across browser contexts
  • Handling infinite scroll and lazy-loaded content
Docs
playwright.dev/docs/frames & /docs/pages
iFrame and multi-page docs — both needed for this session
Practice
the-internet.herokuapp.com
A treasure chest: iFrames, alerts, auth, drag/drop, dynamic loading — each as a separate challenge
15-min Review Self-check questions
  • What's the correct way to interact with an element inside a nested iframe?
  • How do you assert that a download completed and check the filename?
  • What's the event pattern for handling a link that opens in a new tab?
15
CI/CD Integration
Advanced CI/CD GitHub Actions
▾
Ship a working GitHub Actions workflow that runs Playwright tests on every PR. Understand artifacts, caching, and environment variable handling in CI.
  • Playwright official GitHub Actions YAML template
  • Installing browsers in CI: npx playwright install --with-deps
  • Caching browser binaries for faster CI runs
  • Uploading HTML reports and traces as artifacts
  • Environment variables: .env locally vs CI secrets
  • Sharding across multiple CI machines
  • Configuring for GitLab CI, CircleCI, Azure DevOps (overview)
Docs
playwright.dev/docs/ci-intro & /docs/ci
The CI intro is a 5-minute setup; the full CI page covers all providers
Practice
Create a GitHub repo and push a working Actions workflow
Real CI run before this session ends — don't just read the YAML, run it
15-min Review Self-check questions
  • Why do Playwright tests need --with-deps in CI but not locally?
  • Where do you store sensitive test credentials in GitHub Actions?
  • How do you make the HTML report accessible after a CI failure?
Phase 4
Professional & Capstone
16
TypeScript Patterns for Test Engineers
TypeScript Types DX
▾
Apply TypeScript to make your test suite type-safe and self-documenting. Focus on the subset of TypeScript that matters most for test engineering.
  • Typing fixtures with test.extend<{}>()
  • Interfaces for Page Object classes and data models
  • Enums and union types for test data constants
  • Generic helpers for repeated assertion patterns
  • Utility types: Partial<>, Pick<> for test data builders
  • tsconfig best practices for test projects
  • Type-safe environment variables with a config module
Guide
"TypeScript for Playwright" — Stefan Judis / Checkly blog
Search "TypeScript Playwright test patterns" — several excellent community posts on this
15-min Review Self-check questions
  • How do you type a custom fixture that returns a logged-in page object?
  • Write a UserData interface with 5 fields for a test data builder.
  • What's the benefit of typing your environment config vs using process.env.X directly?
17
Performance Testing & Accessibility
a11y Performance Axe
▾
Add accessibility and basic performance measurements to your test suite. These are force-multipliers that many teams overlook until it's expensive to fix.
  • Accessibility testing with @axe-core/playwright
  • checkA11y() — configuring rules, disabling false positives
  • Performance metrics via Chrome DevTools Protocol (CDP)
  • page.evaluate(() => performance.timing)
  • Core Web Vitals: LCP, CLS, FID — measuring in tests
  • Lighthouse CLI integration for performance budgets
  • Network throttling with browser contexts
Repo
github.com/dequelabs/axe-core-npm/tree/develop/packages/playwright
Official axe-playwright package — README has everything you need to get started
Docs
playwright.dev/docs/accessibility-testing
First-party accessibility testing guide added recently — concise and practical
15-min Review Self-check questions
  • What does checkA11y actually check — and what does it NOT check?
  • How would you set a performance budget (e.g., LCP under 2.5s) in a Playwright test?
  • What's one accessibility violation that automated tools always catch, and one they never catch?
18
Reporting, Observability & Test Data
Reporting Allure Test Data
▾
Build professional-grade reporting and test data management. Learn to make test results readable for non-engineers and scale test data safely.
  • Built-in reporters: html, json, junit, dot, line
  • Configuring multiple reporters simultaneously
  • Allure Playwright reporter — installation and rich reports
  • test.info().attach() — adding custom artifacts to reports
  • Test data strategies: static fixtures, factories, faker.js
  • Data isolation: unique data per test run (timestamps, UUIDs)
  • Cleaning up test data after runs
Docs
playwright.dev/docs/test-reporters
Short page — configure 3 different reporters and compare the outputs
Repo
github.com/allure-framework/allure-playwright
Allure Playwright — 5-min setup, professional-grade reports with history, steps, attachments
15-min Review Self-check questions
  • Why is unique test data per run important for parallel test execution?
  • How do you attach a screenshot with a custom name to an Allure report?
  • What's the difference between a JUnit reporter and an HTML reporter in CI context?
19
Component Testing & Playwright Experimental
Components React Experimental
▾
Explore Playwright's component testing for React/Vue/Svelte. Understand when to use component tests vs E2E and how they complement each other.
  • Component testing setup: @playwright/experimental-ct-react
  • Mounting components: mount() fixture
  • Passing props, slots, and event handlers in tests
  • Component vs E2E: the testing trophy applied to Playwright
  • When component testing beats Storybook testing
  • Browser extension testing overview
  • Playwright's roadmap and upcoming features (check release notes)
Docs
playwright.dev/docs/test-components
Mark as experimental/evolving — understand the API but don't build critical infra on it yet
15-min Review Self-check questions
  • What's the key difference between a component test and a unit test for the same React component?
  • When would you choose component tests over E2E tests, and vice versa?
  • What does "experimental" mean for production adoption decisions?
20
Capstone: Full Test Suite End-to-End
Capstone Integration Portfolio
▾
Build a complete, professional test suite from scratch as your portfolio project — integrating every pattern learned across all 20 sessions.
  • Target app: saucedemo.com or automationexercise.com
  • Page Objects for all major pages
  • Custom fixtures for auth (stored state) and page objects
  • 15+ tests: login, product search, cart, checkout, error states
  • API test: verify product count via API before UI assertion
  • Visual regression snapshot on the product page
  • GitHub Actions workflow that runs and publishes the HTML report
  • README documenting how to run locally and in CI
Repo
Your GitHub — push this publicly
This is your Playwright portfolio artifact. Link it in your resume/LinkedIn.
Reference
All 19 previous sessions + playwright.dev
You have everything you need. Build without looking things up first — check docs only when stuck.
15-min Final Review 🎉 You've completed 20 hours of Playwright
  • Which of the 4 phases felt strongest? Which was weakest — revisit that phase's sessions.
  • What would you add next? (Mobile testing with devices, Electron, BDD with Cucumber, cloud services like BrowserStack)
  • Push the capstone repo. You now have a professional Playwright portfolio piece.