Creating a service test with Playwright
You’ve already seen how Playwright can be used to create end-to-end tests that drive the application through the web browser interface. It can also be used to drive the API endpoints directly, and that’s what you’ll learn to do in this section. The benefit of writing up-front Playwright API tests is that we can very carefully plan out how our API will look.
We’ll write just a single test named creating and reading a birthday
. It will do two things: first, create a request to POST
/api/birthdays
that will create a birthday. Then we’ll call GET
/api/birthdays
and check that the previously created birthday is returned in the response:
- Create a new file named
tests/api/birthdays.test.js
with the following content, which is the first half of that test:import { expect, test } from '@playwright/test'; test('creating and reading a birthday', async ({ request }) => { ...