Exit course
Chapter 1 of 9 Intermediate 5 min read Updated

Playwright API Testing: a Hands-On Course

API testing with Playwright in TypeScript: the request fixture, typed JSON assertions, token auth, API data setup for faster UI tests, schema checks, mocking with page.route, and CI plus a cloud grid.

What you will learn

  1. Playwright API Testing: a Hands-On Course
  2. The request Fixture and APIRequestContext
  3. Asserting Status, Headers and JSON
  4. Authentication: Tokens, Test Accounts and storageState
  5. Test Data Setup and Teardown Through the API
  6. Schema Validation with zod and ajv
  7. Mocking APIs with page.route
  8. Running API and UI Tests in CI and on a Cloud Grid
  9. Knowledge Check
On this page
  1. Why test APIs with Playwright at all?
  2. The demo application
  3. How the course is organised
  4. What you'll build
  5. Prerequisites

Last reviewed November 2026 against @playwright/test 1.65.0, zod 4.6.7 and ajv 8.20.0.

Most people meet Playwright as a browser automation tool. It is also a capable HTTP client: every Playwright Test project has a built-in request fixture that sends GET, POST, PUT, PATCH and DELETE requests, keeps cookies, and plugs into the same runner, reporter, retries and traces as your browser tests. This course teaches Playwright API testing the way it pays off most in practice: as part of the same suite as your UI tests, not as a separate tool.

Why test APIs with Playwright at all?#

Dedicated API tools exist, and if your team only tests a public API, one of them may be the better fit. The case for doing API work inside Playwright is strongest when you also have browser tests:

  • One runner, one report. API checks and UI checks run with the same command, show up in the same HTML report, and use the same retries, projects, tags and CI job. There is no second pipeline to maintain.
  • Shared authentication. The token your API tests use can log the browser in too. Chapter 3 turns an API login into a browser session without ever touching the login form.
  • Fast, reliable test data. This is the big one. A UI test that first clicks through five screens to create the record it wants to test is slow and fails for reasons that have nothing to do with what it tests. Creating that record with one API call, and deleting it afterwards, is the single biggest speed and stability win most UI suites can make (chapter 4).
  • Checks from both sides. A test can act in the browser and then ask the API whether the server really changed, or create data through the API and check that the UI shows it.
  • Typed code. Responses become TypeScript types, and a schema library such as zod can check them at runtime (chapter 5).

What Playwright does not try to be: a load-testing tool, a GUI for exploring APIs, or a contract-testing broker. The course points out where those tools fit.

The demo application#

The examples run against the Toolshop at practicesoftwaretesting.com, a public practice web shop built for training testers, with a REST API at api.practicesoftwaretesting.com. It is a good fit because it has both halves: an Angular front end and a real API with token authentication, where writes are actually stored. You can register customers, add favorites and delete them again, and the shop's UI shows the result.

A couple of examples in chapter 1 also use JSONPlaceholder (jsonplaceholder.typicode.com), which is handy for a first request but fakes its writes: a POST returns 201 Created with a new id, yet nothing is saved. Chapter 1 shows a test that proves it. Keep that in mind when you pick a demo API to practise on: a fake write can make a broken test look green.

Both are shared public services. They may be slow, rate-limited or briefly down, and you are sharing data with everyone else who practises on them, which is exactly why the course creates its own customer for each test worker instead of using a shared login.

How the course is organised#

  1. The request fixture: a first API test, baseURL, and the difference between request, page.request and contexts you create yourself.
  2. Asserting status, headers and JSON: toBeOK(), matchers for partial JSON, TypeScript types, and readable failures.
  3. Authentication: token login through the API, worker-scoped test accounts, and starting browser tests already logged in.
  4. Test data through the API: fixtures that create data before a UI test and clean it up after, and checking UI actions on the server.
  5. Schema validation: zod and ajv, and what a published OpenAPI schema does and does not guarantee.
  6. Mocking with page.route: fake, modify and break API responses the browser sees, and when not to.
  7. CI and the cloud grid: what runs where, which tests need a browser, and running the browser half on TestingBot.
  8. Knowledge check.

What you'll build#

One TypeScript project with three Playwright projects:

  • api: twelve API tests that never start a browser,
  • chromium and firefox: UI tests whose data is created through the API and whose browsers start logged in,
  • plus a second config that runs the same UI tests on remote Windows and Linux browsers on TestingBot.

Prerequisites#

This course builds on the free Playwright tutorial and links back to it instead of repeating the basics. You should be comfortable with:

You also need Node.js 22, 24 or 26, a code editor, and for chapter 7 a TestingBot account (the free trial is enough).

The course is free and needs no account. If you want something to show for it, the optional TestingBot certification asks for a passed exam and this course's suite running green on TestingBot. It is issued by TestingBot; Microsoft and the Playwright project do not offer a Playwright certification.