Skip to content

Series

End-to-End Tests With Playwright: Frontend, Backend and Database

Set up Playwright for a whole app, in four sections that each have a job: the database, the API, the frontend against a mocked API, and a few flows through all of it. In parallel, with a database per worker, and in your pipeline at the end.

Intermediate14 parts · about 6 h

Fourteen parts, from a small app without a single test to a suite that checks every layer on every push. The app is a quest board with a Vue frontend, a Hono API and a PostgreSQL database, and the suite gets one Playwright project per layer: the database tests talk SQL, the backend tests send requests, the frontend tests run a browser against a mocked API, and a handful of end-to-end tests go through everything at once. When something breaks, the section that turns red tells you where to look. You give every parallel worker a database and a server of its own, so tests never see each other, learn to read a trace when one fails, log in once for the whole suite, and add accessibility checks and screenshot comparisons. At the end GitHub or GitLab runs all of it in the same container that runs it on your machine.

Start with part 1

Quest line

  1. The App Under TestSee how the suite of this series is laid out, in four sections that each have a job, then build the small app it tests: a quest board with a Vue frontend, a Hono API and a PostgreSQL database.35 min
  2. Your First Playwright TestInstall Playwright, let it start the app by itself, and write a test that opens the quest board in a real browser and adds a quest. Then find out why a green test can still be wrong.20 min
  3. One Config, Four ProjectsSplit the suite into four Playwright projects, one for each layer of the app: database, backend, frontend and end to end. Each gets a first small test that shows what kind of test lives there.20 min
  4. A Database for Every WorkerGive every parallel worker its own copy of the database, made from a template that the real migrations build, and every test empty tables. Tests then run in parallel and in any order, and your development data is left alone.25 min
  5. Testing the DatabaseFill the database section: tests for the defaults and constraints of the table, for the queries the app sends, and one test that notices when schema.ts has changed and the migration for it is missing.25 min
  6. Testing the BackendLet every worker start its own copy of the API on its own database, then test every endpoint with real HTTP requests: the status, the body, and the row that is in the database afterwards.25 min
  7. Testing the FrontendTest the page in a real browser while the test plays the API: a page object, a guard against requests nobody mocked, and twelve tests for states a real backend rarely shows, from loading to unreachable.30 min
  8. End to End, Through All LayersBuild the frontend, let every worker's own server hand it out, and write five tests that go through browser, API and database at once. After this, no test touches your development setup any more.25 min
  9. When a Test FailsBreak the app on purpose and follow the trail: which sections turn red, what the error says, and how the trace shows the page, the actions and the network at the moment it went wrong.25 min
  10. A Login for the Quest BoardThe app grows: everyone may still read the quest board, but only members who are logged in may change it. Build the login through all three layers, run the suite, and read why half of it turns red.30 min
  11. Log In Once, Test EverywhereLet a setup project log in a single time, save the cookie as storage state, and start every test that needs a member with it. The red tests turn green without a change, and the login gets tests of its own in all four sections.35 min
  12. Accessibility Checks With axeLet axe look at four states of the quest board on every run, fix what it finds, and then fix what it could not find: a field whose label nobody ever sees. An ARIA snapshot pins down what a screen reader is told.20 min
  13. Visual ComparisonsTake pictures of the quest board and let Playwright compare them on every run, so a CSS change that moves something shows up as a failed test. The pictures are always made in the same container, because that is the only place where they compare well.25 min
  14. The Tests in Your PipelineLet GitHub or GitLab run all four sections on every push, in the same container that runs them on your machine, with a database beside it and the report kept for every run, red ones included.20 min