Playwright in practice
A hands-on course in Playwright, a popular tool for automating browser tests. Install it, write a first test, find elements, wait the right way, check results, mock the network, run in parallel and on a pipeline, and fix flaky tests. Every topic uses the same made-up to-do app.
PAGE OVERVIEW
A hands-on course in Playwright, a popular tool for automating browser tests. Install it, write a first test, find elements, wait the right way, check results, mock the network, run in parallel and on a pipeline, and fix flaky tests. Every topic uses the same made-up to-do app.
- What Playwright is, and how it drives a browserPlaywright opens a real browser and follows the steps your test code gives it. See what it does, why testers pick it, and what it cannot judge.
- Install Playwright and run your first testSet up a new Playwright project with one command, write a first test for Daily List, run it, and open the report. Fix the two errors new users meet most.
- The project layout and the config fileLearn what each folder and file in a Playwright project is for, and what goes in the config file: where tests live, the base address, and the browsers to run.
- Record a test with codegen, then make it yoursUse Playwright's recorder to write a first draft of a test from your clicks, then fix its weak spots: add real checks, clear names and no hard-coded data.
- Running tests: the command line, headed mode, filters and tagsRun all tests, one file, one browser or only the tests with a tag. Watch a test in a visible browser, and learn the flags that new users mix up.
- TypeScript, JavaScript, Python, Java or .NET: choosing a Playwright languagePlaywright speaks several programming languages. See what stays the same, what changes with each one, and how a team can choose with a small trial instead of a guess.
- Finding elements: getByRole, getByLabel, getByText and test idsAsk for an element by its job, its label or its words, as a person would, and keep test ids for when nothing else fits.
- Narrowing locators: chaining, filtering, lists and nthWhen a locator matches many rows, search inside one row instead of counting positions, and let strict mode warn you when you were not exact.
- Acting on the page: click, fill, check, select, hover, drag and keysLearn the few verbs a test uses on a page, pick the one that matches what a person does, and leave force for the rare case.
- Auto-waiting: what Playwright checks before it actsBefore it clicks or types, Playwright waits until the element is ready, so most hand-written waits are not needed. Learn what it checks and what it cannot.
- Web-first assertions: expect that keeps tryingCheck the page with an assertion that keeps trying until it is true or time runs out, and keep one-shot checks for values you already hold.
- Soft assertions, timeouts and clear failure messagesSee every wrong fact in one run with soft assertions, know which time limit ran out, and write a failure message that tells the next person what broke.
- Test structure: describe, hooks, tags, annotations and skippingGroup Playwright tests with describe, share set-up with hooks, label them with tags, and mark tests that must wait with skip or fixme.
- Fixtures: shared setup without copy-pasteA Playwright fixture builds set-up before a test, hands it over by name and cleans it up after, so tests only say what they need.
- Page objects in PlaywrightWrap one page in a TypeScript class with locators and action methods, so a Playwright test says addTask and not a string of clicks.
- Isolation: browser contexts and a fresh state for every testPlaywright gives each test a fresh browser context. Learn what that isolates, what it does not, and how to act as two users in one test.
- Logging in once: authentication and storage stateLog in once in a setup test, save the browser state to a file and load it in every test. Keep the file secret and refresh it when it goes stale.
- Projects, setup projects and test dependenciesA Playwright project is a named set of settings. Learn to run the same tests in several browsers and to run a setup project first with dependencies.
- API testing with the request fixtureCall the Daily List server directly with Playwright's request fixture, check the answers, and use it to set up data fast.
- Network interception: route, mock, change and wait for requestsUse page.route to answer, change or block the calls a page makes, and wait for calls with waitForResponse, so every page state can be tested.
- Frames, tabs, dialogs and popupsReach inside frames, answer dialog boxes and follow a link into a new tab, with the Playwright calls that do each one and the mistakes to avoid.
- Uploads and downloadsAttach a file to a task with setInputFiles, catch the file chooser, and wait for a download to check its name and content.
- Devices, locale, geolocation and permissionsRun the same Daily List test as a phone, in German, in another time zone and at a made-up place, with the Playwright options that set each one.
- Controlling time: the clockInstall Playwright's fake clock to freeze the date or skip ahead, so a 9 a.m. reminder or a 30-minute timeout is tested in a blink.
- Screenshots and visual comparisonsTeach a Playwright test to take a picture of a page, compare it with a saved one, hide moving parts and update the saved picture on purpose.
- Accessibility checks with axe in PlaywrightAdd an axe accessibility scan to a Playwright test, read what it reports, choose its rules, and keep clear about what a scan cannot judge.
- Debugging: inspector, UI mode and the trace viewerFind out why a Playwright test failed by stepping through it with the inspector and UI mode, or by replaying a recorded trace afterwards.
- Parallel runs: workers and shardingRun Playwright tests at the same time with workers on one machine and shards on many, and keep them from stepping on each other's data.
- Retries and flaky testsUse Playwright retries to learn which tests are flaky and to gather evidence, without letting them hide the problem or become the cure.
- Reporters and artifacts: reports, screenshots, videos and tracesChoose Playwright reporters for people and for build tools, record screenshots, videos and traces only when they pay off, and keep them after a failed run.
- Playwright in a pipeline: GitHub Actions and containersRun Playwright tests on every change in a GitHub Actions workflow. Choose between installing browsers and using the official Docker image. Keep the report when a run fails.
- Component testing with PlaywrightTest one piece of a page in a real browser, without logging in or loading the whole site. Learn what a story, a gallery and the mount fixture are.
- AI-assisted test writing and the Playwright MCP serverLet an artificial intelligence (AI) helper see the page through Playwright Model Context Protocol (MCP) and draft tests. Check every line and prove it can fail.
- Playwright, Selenium and Cypress: choosing a toolCompare three browser test tools by how they drive the browser, how they wait and what they cost a team. Choose by running the same small trial, not by fashion.
- Capstone: a complete Playwright suite for Daily ListPut the whole course together. Choose what to test, lay out the project, log in once and seed data. Mock the awkward parts, run on a pipeline and keep the suite healthy.
- TypeScript for Playwright testers: just enough to read and write testsA small set of TypeScript phrases is enough to read a Playwright test, write your own, and spot the one mistake that breaks most beginner tests.
- Playwright with Python and pytestThe same Daily List test written in Python: install the pytest plugin, get a page for free, and learn the few names that change from the TypeScript version.
- Aria snapshots: checking the page structure as a treeCheck the roles and names that make up a page, as a text tree, so a restyle does not break the test but a lost button or heading does.
- Running JavaScript in the page: evaluate, handles and init scriptsRun a small piece of code inside the page to read or set something, know what a handle is, and keep clicks and checks on locators.
- Custom selector engines and test id attributesChange which attribute getByTestId reads, and learn how a custom selector engine is built and registered, and why it is the last tool in the box.
- Listening to the page: console messages, page errors and eventsListen to what the page says in its console and what breaks inside it, and make the test fail when the page shouts, even if every click works.
- Tricky widgets: date pickers, tables, drag and drop and rich textHandle four awkward parts of a page: fill or pick a date, find a row in a table, drag one item onto another, and type into a text box that formats.
- Steps, test info and attachmentsName the parts of a long test so the report reads like a story, and attach screenshots or notes to a result so a failure comes with its evidence.
- Parameterized and data-driven tests, and environment variablesWrite one test and run it with many sets of data, and switch the site address or a secret from outside the code, without copying the test.
- Test data management for Playwright suitesGive every test the data it needs, keep parallel tests from fighting over the same records, and clean up afterwards so the next run starts fresh.
- Email, one-time codes and multi-factor sign-in flowsTest a sign-in that sends a code by email or needs an authenticator app code: catch the mail, make the code at run time, and know when a test-only bypass is fair.
- Polling and retrying blocks: expect.poll and toPassWait for a value that is not on the page, such as an answer from the server, by checking again and again until it is right or time runs out.
- Recorded traffic and WebSockets: HAR files and routeWebSocketRecord the real conversation between the page and the server once, replay it in later runs, and stand in for a live WebSocket feed when a test needs one.
- Mocking browser APIs: clock, geolocation, clipboard and moreReplace parts of the browser with stage props, such as the time, the place, the clipboard or the battery, before the page loads, so a test can control what the page sees.
- Remote browsers, cloud grids and library modeRun Playwright tests in a browser that lives on another machine, such as a cloud grid, and learn when to use Playwright as a plain library instead of the test runner.
- Beyond the browser tab: service workers, offline mode, Electron, Android and WebView2Test what lives around a web page: a service worker that keeps the app working offline, and desktop or phone apps that hold a web page inside them.
- BDD with Cucumber and PlaywrightWrite Daily List checks as plain-language scenarios that Nina can read, then connect each line to a Playwright step. Learn two ways to join them and what each costs.
- Keeping test code clean: linting, formatting, hooks and reviewUse a linter, a formatter, a type check, a git hook and a short review list so Playwright test code stays tidy and mistakes such as a missing await are caught before they run.
- Best practices and anti-patternsOne place to read the habits that keep Playwright tests steady, and the habits that make them break. Each habit has a reason, a Daily List example and a fix.
- The editor workflow: the VS Code extension and running tests as you writeInstall the Playwright extension in Visual Studio Code, run a test with one click, watch the browser, pick a locator from the page and fix a test without leaving the editor.
- Test agents and the Playwright CLI for coding agentsMeet the planner, generator and healer agents that ship with Playwright, and the command line tool made for coding agents. Learn what each does, and how a tester stays in charge.
- Moving to Playwright from Puppeteer, Protractor, Selenium or CypressMove an old browser test suite to Playwright in small safe steps: carry the ideas across, leave the old habits behind and keep both suites running until the new one matches.
- From testing to monitoring: running Playwright checks against productionReuse a Playwright test as a check that runs on a timer against the live site, so the team hears about a broken sign-in before users do.
- Playwright interview preparation: the questions and how to answer themPractise the questions that interview guides ask about Playwright, with a short plain answer for each and a pointer to the lesson that teaches it.
- Staying current: release notes, upgrades and reading the docsUpgrade Playwright on purpose: read the release notes first, update the browsers, run the suite on a branch and fix what the notes warned about.