Playwright lab
API testing with request
Mix the request fixture and the UI: create data over HTTP, then verify it in the browser.
Practice tasks
- Read the sandbox id shown on the page (or localStorage 'ty.sandbox') and send it as the X-Sandbox header.
- POST /api/users with request.post(), reload the page and assert the new user appears in the table.
- Create a user in the UI form and verify it with request.get('/api/users/:id').
- Delete the user with the row button and assert request.get() now returns 404.
- Validate the 400 error body (errors array) when name is empty.
- Use request.newContext({ baseURL, extraHTTPHeaders }) for a standalone API client in a fixture.
- Chain calls: create → patch → get → delete, asserting status codes 201, 200, 200, 204.