Task Progress0 of 4 Tasks
0%

API Testing & Network Interception

A working mini API client. Use your tool’s network layer to mock responses, force error codes, rewrite requests and cut the connection. The page checks what came back, so each task ticks itself once your interception works.

1.API client

Response
Hit Send to get a response

2.Tasks

Mock a responseTo do

Use the API client above.

Goal

Send a GET request and make it come back as 200 with the body {"message": "Intercepted!"}, without the request reaching the real server.

Force error codesTo do

Seen so far: none

Goal

Make one request come back as 404 and another as 500.

Rewrite a request in flightTo do

Use the API client above.

Goal

Set the method to POST with the body {"role": "user"}. Change role to admin on the way out, so the server echoes back admin.

Cut the connectionTo do

Use the API client above.

Goal

Make the request fail at the network level, as if the user went offline.

About this API Interception page

API interception is a testing technique where your test captures a request the page sends and either answers it with fake data, changes it, or blocks it. In Playwright you use page.route, in Cypress cy.intercept, and in Selenium 4 the DevTools or BiDi network APIs. This page makes real fetch calls so you can practice each approach for free in the browser.

Screenshot of the API Interception practice page on QA Playground. Mock and modify network requests directly.
API Interception: Mock and modify network requests directly.

Frequently asked questions

How do you mock an API response in Playwright?

Call page.route with a URL pattern before the action that triggers the request, then use route.fulfill with a status, headers and JSON body. Use route.continue to let a request through, optionally with changes, and route.abort to simulate a network failure.

How do you intercept network requests in Cypress?

Use cy.intercept with a method and URL to stub a response or spy on traffic. Give it an alias with .as, then cy.wait the alias to assert on the request body or response status. Define the intercept before the click that fires the request.

Can Selenium intercept and mock network requests?

Yes, in Selenium 4. Selenium Java offers NetworkInterceptor and Python uses the Chrome DevTools Protocol through execute_cdp_cmd, with BiDi network commands as the newer route. It is more verbose than Playwright or Cypress and works best in Chromium browsers.

Why mock APIs in UI tests?

Mocking makes tests fast and repeatable and lets you force states that are hard to reach for real, such as 500 errors, empty lists, slow responses and timeouts. Keep a few unmocked end-to-end tests so real integration still gets checked.

Do I need to sign up or install anything to practice here?

No. The page is free and runs in the browser. Point your own Playwright, Selenium or Cypress project at it, finish the tasks, and the result box shows which ones passed. Reference solutions in four frameworks are available when you get stuck.

Free developer tools on Randomly.online

QA Playground is part of Randomly.online. These tools help while you write and debug tests: