Playwright lab
Network mocking
A UI that calls real API endpoints and logs every request: mock, block, delay and wait for them.
Practice tasks
- Use page.route('**/api/products*') with route.fulfill() to show exactly two fake products.
- Fulfil /api/users with an empty list and assert the empty-state message.
- Abort the advertisement image with route.abort() and assert it did not load.
- Use page.waitForResponse() to wait for /api/products while clicking the button, then assert response.status().
- Mock /api/flaky with 503 and assert the error alert; then use route.fallback() / route.continue() to pass real calls through.
- Modify a real response: fetch it with route.fetch(), change a price and fulfil with the patched JSON.
- Run the type-ahead search and find the stale-response race: how do you assert only the latest results are shown?
- Listen to page.on('request') and page.on('response') and compare with the on-page request log.