arrow-left Back to topicQuizMock APIsCheck yourself1.You want a test to always see exactly 3 orders regardless of the database state. Which approach is cleanest?page.route() with route.fulfill({ json: [...] }) — intercept and return your own JSONRecord a HAR file with update: true, then replay with update: falseroute.fetch() the real response and filter it to 3 items2.When is a HAR file better than writing inline route handlers?Always — HAR is the recommended approach for all mockingWhen the flow involves many requests with complex payloads that are too tedious to hand-craftOnly when the API returns binary data like images3.What is the difference between route.fulfill() and route.abort() in a page.route() handler?route.fulfill() returns a response to the browser; route.abort() cancels the request so the browser gets a network errorroute.abort() returns a 404; route.fulfill() returns a 500They are identical — both prevent the request from reaching the serverroute.fulfill() only works with JSON; route.abort() works with any content type4.You have a route handler set up for '*/**/api/orders'. A request to '/api/users' is made. What happens to that request?It is blocked by default — all unmatched routes are abortedIt proceeds to the real server normally — unmatched requests are not interceptedIt throws an error because no handler is registered for that URLIt matches the handler because '**' is a wildcard that covers all paths5.How do you write a glob pattern in page.route() to match any URL containing '/api/orders' regardless of origin?'/api/orders''**/api/orders' or '*/**/api/orders''^/api/orders$' — use regex syntax in glob patterns'http://*/api/orders'6.You set up a route mock in a test but want to remove it partway through so subsequent requests go to the real server. What do you call?page.route() with the same pattern again to overwrite itpage.unroute(pattern) to remove the handler for that patternroute.continue() inside the handler to pass all requests throughpage.reload() clears all route handlers automatically7.You want to mock an API endpoint using data from a local JSON file. What is the correct approach?page.route('**/api/orders', route => route.fulfill({ path: './fixtures/orders.json' }))You cannot use local files — route.fulfill() only accepts inline JSON objectspage.route('**/api/orders', route => route.fulfill({ url: 'file://fixtures/orders.json' }))import data from './fixtures/orders.json' then route.fulfill({ body: JSON.stringify(data) })8.When using route.fetch() to get the real response and then route.fulfill({ response, json }), why do you pass the original response object?It is required — route.fulfill() throws without a response objectPassing the original response preserves its status code, headers, and cookies — only the body is replaced by jsonIt is for logging purposes only — Playwright ignores the response objectIt tells Playwright to replay the request if it failsSubmit answersarrow-left PreviousNetworkAPI testingNext arrow-right