Managing Network Requests in Cypress: Choosing Between Intercept and Route
Learn when to use cy.intercept() over the deprecated cy.route() to handle asynchronous network requests, stub API errors, and avoid the pitfalls of contract drift in Cypress.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Learn when to use cy.intercept() over the deprecated cy.route() to handle asynchronous network requests, stub API errors, and avoid the pitfalls of contract drift in Cypress.
Playwright's page.route() intercepts network requests at the browser layer, letting you mock APIs without external dependencies. This post shows a concrete pattern for reliable UI tests, common pitfalls with pattern matching and content-type, and how to verify mocks actually fired using traces.
Decide when to stub API calls with cy.intercept() or hit the real endpoint with cy.request() in Cypress. A practical guide compares speed, reliability, maintenance, and contract validation, then shows concrete test snippets and how to measure trade‑offs.
Learn how to mock external API calls in Playwright using network request interception. This guide covers prerequisites, step‑by‑step procedure with code examples, expected checks, and recovery options to keep your E2E tests deterministic and fast.
Use Puppeteer’s request interception to replace real API calls with mock responses, making end‑to‑end tests stable and fast. The post walks through a concrete example, highlights trade‑offs, and offers best‑practice tips.
Learn how to replace real backend calls with controlled stubs in Cypress, ensuring fast, deterministic tests. Follow this step‑by‑step guide to set up cy.intercept, validate requests, and handle failures.
Move beyond arbitrary cy.wait() calls. Cypress cy.intercept() enables deterministic API mocking, latency simulation, and contract validation across e2e and component tests—with practical patterns for GraphQL, binary payloads, and early-request blind spots.
Learn how to use Puppeteer’s request interception to mock API calls, speed up tests, and keep UI logic isolated. A concrete example, trade‑offs, and best‑practice checklist are included.
Playwright's route() and fulfill() let you mock HTTP responses in cross-browser E2E tests, while browser contexts and serial() isolate state and prevent interference.