Skip to main content

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.

Quiz

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
B. Routing lets you produce the failure on demand, in every run, with the API’s real error shape.
Quiz

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
B. With an aborted request there is no server message, so the browser supplies one. Assert on the part your application controls, here the prefix “Could not load products:”.
Quiz

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
B. A full stub is fully under your control. Modifying a real response keeps everything else realistic and changes only what the test is about.
Quiz

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
B. A mock proves the frontend handles the response you gave it. Only tests against the real backend notice when that response changes.
Quiz

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
B. 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.
Quiz

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
B. For money and orders, what must not happen matters as much as what must. toHaveCount(0) on the success screen turns that into a check.