lecture 3 of 180 completed

Faking the server's answer

page.route lets you test hard situations like server errors. It is powerful, and it has a cost you must understand.

What you'll learn

  • How to test states you cannot easily create
  • What mocking costs you in real coverage
  • Which paths must stay unmocked

This builds on request interception, so it is also something you run on a local project rather than in the editor here. The technique is standard on real teams, and interviewers ask about its trade-off often.

Your manager asks a reasonable question: "What does the app show when the server is down?"

You want to test it, but you cannot break the real server just to run a test.

Playwright lets you answer the request yourself. This is called mocking or stubbing: your test gives a fake answer instead of letting the request reach the real server.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →