Knowledge Check
Nine questions on the decisions that matter most when API tests and UI tests share one Playwright suite. Each answer comes with a short explanation, so a wrong answer points you back to the right chapter.
1. Your config has three projects, api, chromium and firefox, but no testDir per project. What happens to a file of pure API tests?
Projects run every test file they match, regardless of the fixtures a test uses. Giving each project its own testDir (or testMatch) keeps API tests in one project.
2. Inside a test in the chromium project (whose baseURL is the UI host), you call playwright.request.newContext() without options and then get('/products'). Where does the request go?
Request contexts created during a test pick up the project's use options for anything not set explicitly. Pass baseURL yourself when the API lives on another host.
3. A test checks that deleting an order works: it calls DELETE /orders/7 and asserts toBeOK(). What should it add to really prove the delete?
A success status is the server's claim. Reading the record back is what shows it is gone; failOnStatusCode only changes how an error status is reported.
4. Four workers share one test customer account. A test asserting "the cart has exactly one item" fails about once in five runs. What is the structural fix?
Workers run in parallel on the same account and change each other's data. One account per worker isolates them and keeps the parallelism; retries only hide the collision.
5. You override storageState in your base test with a fixture that logs in through the API. API-only tests now take noticeably longer. Why?
The built-in context options, including storageState, are set up for every test. A login hidden in that override runs for API tests too. Put it in a separate fixture layer that only UI tests import.
6. A fixture creates a project through the API, calls use(), then deletes it, wrapped in try { ... } catch {} so cleanup never fails a test. What is the risk?
Swallowing every cleanup error hides real bugs. Accept the specific outcomes you expect (for example 204 or 404 if the test may have deleted it already) and let anything else fail.
7. Which statement about a consumer-written zod schema and the API's published OpenAPI schema is accurate?
They answer different questions. Published schemas often list properties without marking them required, so a response missing fields can still validate. The consumer schema is the one that protects your front end.
8. You want a UI test of the "search is down" state. Which approach fits?
Routing lets one test break one endpoint for one browser context without touching shared infrastructure. A request through request does not affect what the page sees.
9. Your API tests and UI tests run with one config whose browser projects connect to a cloud grid. Which tests open grid sessions?
connectOptions is set per project. Tests in the API project never ask for a browser, so they open no session and run on the machine that started the run.
Where to go next#
If you have not yet worked through the browser side in depth, the Playwright tutorial covers locators, debugging and parallel runs. To run your suite on more browsers and operating systems, the Playwright documentation for TestingBot lists every option. The official Playwright API testing guide and the zod documentation are both worth reading end to end.
You finished Playwright API Testing Tutorial
Put what you learned into practice. Run your tests on 6100+ real browsers and physical iOS and Android devices.