Quiz: Network interception and mocking
Why This Matters
A quick check that this module’s ideas hold up before you move on. Answer each question yourself before you open the answer.
1. You want to test the shop’s error message when checkout fails. What is the most reliable way?
- A. Wait until the real backend has an outage
- B. Fulfill the checkout request with a 5xx response using
page.route - C. Turn off the network on your machine
- D. Skip the test; error states are rare
Show answer
2. A test uses route.abort("failed") and asserts the full error text. It passes in Chromium and fails in Firefox. Why?
- A. Firefox does not support
route.abort - B. The part of the message after the shop’s prefix comes from the browser, and each browser words it differently
- C. Firefox caches the products
- D. The test needs a longer timeout
Show answer
3. What is the difference between route.fulfill({ json }) and route.fetch() followed by route.fulfill({ response, json })?
- A. None
- B. The first never calls the server; the second calls the real server and lets you change its answer
- C. The first only works for GET requests
- D. The second is only for HAR files
Show answer
4. Your mocked UI tests all pass, but production breaks because the API renamed a field. What was missing?
- A. More mocked tests
- B. Tests against the real API (or a re-recorded HAR) that check the contract
- C. A longer timeout
- D. Visual tests
Show answer
5. During a HAR replay with notFound: "abort", a search makes a request that was never recorded. What happens?
- A. Playwright sends it to the real server
- B. The request fails, and the page shows its error state
- C. Playwright records it automatically
- D. The test is skipped
Show answer
notFound: "abort" makes unrecorded requests fail loudly. With "fallback" they would go to the real server, and the test would silently depend on it again.6. A checkout test checks that the error message appears. Why also assert that the success screen is not shown?
- A. It makes the test faster
- B. Without it, a page that shows both the error and a success screen would still pass
- C. Playwright requires a negative assertion
- D. It replaces the error check
Show answer
toHaveCount(0) on the success screen turns that into a check.