liveBook · Manning

Playwright

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

Playwright is a browser automation and end-to-end testing framework.

Playwright automates tests against web pages. For an end-to-end test of a microservices application, it opens the frontend in a browser while the gateway, other services, and database are running. These tests are slower than tests of individual services, but they exercise the application from the customer's point of view. section 9.8

Figure 9.9 End-to-end testing our entire application with Playwright and Docker Compose

The diagram shows where Playwright sits when Docker Compose runs the application under test. section 9.8

Start the application before running the tests: `docker compose up --build`. Wait until the gateway is online. Seed the database with a fixture so the browser encounters predictable data; unlike a unit test, this example does not mock the application behind the frontend. section 9.8 section 10.6.2

Check a video list

In an asynchronous Playwright test, load the `two-videos` fixture, then call `page.goto('/')`. The route is relative to the configured base URL. Use `page.locator('#video-list>div')` and `expect(videos).toHaveCount(2)`; then inspect each video's link text and `href`. The `page` argument controls the browser page, while locators select elements from its DOM. section 9.8.5

Run and report the tests:

  • `npx playwright test` runs the suite; `npx playwright test --reporter=list` puts pass and fail results in the terminal, which is useful for CI/CD. section 9.10 section 9.8.5
  • Configure an npm `test` script to run `playwright test --reporter=list --workers 1` when tests share a database. A single worker avoids parallel tests interfering through that shared state. section 9.8.6

Playwright's generated configuration can set up tests across multiple browsers, and its default headless mode suits CI/CD. Visual reports and debugging tools are also available. `npm test` is only a project convention: check its script, since another project may use it to run Jest instead. section 9.8.1 section 10.6.2

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Works through fixtures, page navigation, DOM locators, assertions, and test commands; stops at Playwright basics rather than its full feature set.
Examples
Uses a seeded two-video list to check displayed links, then runs the suite through Playwright commands or an npm script.
What it assumes
Assumes a runnable application, database fixtures, and familiarity with npm and Docker Compose; introduces the Playwright page interface through an example.
What you can do after
Apply it via Playwright to check a running frontend against fixture data and obtain terminal test results.
How it connects
Connects end-to-end testing with Docker Compose, database fixtures, browser frontends, Jest, and CI/CD.

Also explained in

Compare how 2 books explain Playwright →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.