Playwright · Middle · Question 18 of 75
How do you change a real API response slightly, e.g. one field?
await page.route("**/api/user", async (route) => {
const response = await route.fetch();
const json = await response.json();
json.plan = "pro";
await route.fulfill({ response, json });
});- 1Mocking real responses is not supported in Playwright
- 2Use
route.continue()with a new JSON body to answer - 3Fetch it with
route.fetch()and fulfill a modified copy
Show the answer
Correct answer: Fetch it with route.fetch() and fulfill a modified copy
Explanation
This keeps the real backend in the loop while forcing one condition, such as a paid plan.