Introduction: Why Playwright Network Interception Matters in Interviews
Modern web applications depend on APIs to load data, authenticate users, process payments, display products, and update information. A user may see a loading spinner while the frontend waits for a backend response. If the API returns an error or takes too long, the application must handle that situation correctly.
This is where Playwright network interception becomes useful.
Playwright allows automation engineers to monitor, modify, block, and mock HTTP network requests. You can test how an application behaves when an API returns successful data, an error response, delayed data, or no response at all.
Interviewers ask about network interception because it demonstrates more than basic browser automation knowledge. It shows that you understand how the frontend communicates with backend services and how to test applications when external dependencies are unavailable.
In this guide, we cover playwright network interception interview questions from beginner to advanced levels. You will learn the page.route() method, API mocking, request and response events, HAR replay, and practical TypeScript examples.
1. What Is Network Interception in Playwright?
Network interception is the process of capturing and controlling network requests made by a web application.
When a browser sends an HTTP request, Playwright can intercept it before it reaches the server. You can then decide what should happen.
For example, when an application requests:
GET https://example.com/api/products
Playwright can:
- Allow the request to reach the actual server.
- Return a custom response without contacting the server.
- Modify the request URL, headers, method, or body.
- Abort the request to simulate a network failure.
- Fetch the real response and modify it before returning it to the browser.
Playwright provides two important routing methods:
- page.route() – intercepts matching requests made by a particular page.
- browserContext.route() – intercepts matching requests made by pages in a browser context.
The main routing actions are:
| Method | Purpose |
| route.continue() | Sends the request to the actual server |
| route.fulfill() | Returns a custom response |
| route.abort() | Stops the request |
| route.fetch() | Fetches the original response for modification |
These methods help QA engineers test frontend behavior independently of backend availability.
For more details, refer to the official Playwright Network documentation.
2. Benefits of Playwright Network Interception
Why do automation engineers use network interception?
1. Test without backend dependency
You can mock API responses when the backend is unavailable or under development.
You can simulate HTTP errors such as 400, 401, 403, 404, and 500.
3. Improve test stability
Mocking predictable responses can reduce failures caused by unstable third-party services.
4. Validate frontend error handling
You can check whether the application displays the correct message when an API fails.
5. Test loading behavior
You can delay API responses and verify loading indicators.
6. Reduce external API calls
Mocking avoids unnecessary requests to external systems during regression testing.
7. Test different user conditions
You can provide different responses for authenticated users, guest users, administrators, or users with restricted permissions.
8. Support continuous integration
Tests can run in CI/CD environments without depending on every external service being available.
3. Basic Playwright Network Interception Interview Questions
Q1. What is network interception in Playwright?
Answer:
Network interception allows us to capture and control HTTP requests made by a browser page.
Using Playwright, we can modify requests, mock API responses, abort requests, or allow requests to continue to the server.
For example:
await page.route(‘**/api/users’, async route => {
await route.fulfill({
status: 200,
json: {
id: 1,
name: ‘John’
}
});
});
This example intercepts a user API request and returns mock data.
Q2. What is the purpose of the page.route() method?
Answer:
The page.route() method registers a route handler for network requests made by a specific page.
It accepts a URL pattern and a callback function.
Example:
await page.route(‘**/api/products’, async route => {
console.log(route.request().url());
await route.continue();
});
Here, Playwright captures the matching request, prints its URL, and allows it to reach the actual server.
Q3. What is the difference between route.fulfill() and route.continue()?
Answer:
route.fulfill() returns a response directly from the test without sending the intercepted request to the original server.
route.continue() sends the request to the actual server.
Example:
// Return mock data
await page.route(‘**/api/users’, async route => {
await route.fulfill({
status: 200,
json: {
name: ‘Test User’
}
});
});
// Send the request to the server
await page.route(‘**/api/users’, async route => {
await route.continue();
});
Use fulfill() for mocking and continue() when you want the real backend response.
Q4. What is route.abort()?
Answer:
route.abort() stops a network request. It is useful for testing network failures or checking how an application behaves when a resource cannot load.
Example:
await page.route(‘**/api/products’, async route => {
await route.abort();
});
The application will not receive a normal HTTP response for this request.
You can also specify an error code:
await page.route(‘**/api/products’, async route => {
await route.abort(‘timedout’);
});
Q5. What is Playwright API mocking?
Answer:
API mocking means replacing a real API response with predefined test data.
For example, if a product page calls /api/products, we can return a list of sample products instead of contacting the backend.
This helps test the UI independently and makes test results more predictable.
Q6. Is Playwright network interception suitable for beginners?
Answer:
Yes. Beginners can start with a simple page.route() example and learn the three main actions: fulfill(), continue(), and abort().
A good learning sequence is:
- Monitor a network request.
- Intercept a GET request.
- Return mock JSON.
- Simulate an API error.
- Modify request headers.
- Test delayed responses.
Basic TypeScript and HTTP knowledge are helpful, but you do not need advanced backend development experience to get started.
Q7. How do you monitor network requests in Playwright?
Answer:
Use the request, response, and requestfailed events.
page.on(‘request’, request => {
console.log(‘Request:’, request.method(), request.url());
});
page.on(‘response’, response => {
console.log(‘Response:’, response.status(), response.url());
});
page.on(‘requestfailed’, request => {
console.log(‘Failed:’, request.url());
});
These events help investigate network activity during web testing.
Q8. What is the difference between request and response events?
Answer:
The request event is triggered when the browser issues a network request.
The response event is triggered when response status and headers are received.
A request can be issued successfully but receive an HTTP error response, such as 404 or 500. That is still an HTTP response, not necessarily a transport-level request failure.
Q9. What is the difference between requestfailed and an HTTP 500 response?
Answer:
A 500 response means the server returned an HTTP response indicating an internal server error.
A requestfailed event means the browser could not complete the request successfully at the network level, such as when a connection fails or times out.
To validate a 500 response, listen for the response event or use waitForResponse().
Q10. Can Playwright intercept third-party API requests?
Answer:
Yes. Playwright can intercept requests to third-party services when those requests are made through a page or browser context and are not handled outside the routing mechanism.
For example:
await page.route(‘**/analytics/**’, async route => {
await route.abort();
});
This can be useful when analytics calls are not relevant to a particular UI test.
4. Intermediate Playwright Network Interception Interview Questions
Q11. How do you mock a GET API request using TypeScript?
Answer:
Use page.route() and route.fulfill().
import { test, expect } from ‘@playwright/test’;
test(‘Mock GET products API’, async ({ page }) => {
await page.route(‘**/api/products’, async route => {
await route.fulfill({
status: 200,
contentType: ‘application/json’,
body: JSON.stringify([
{
id: 1,
name: ‘Laptop’,
price: 50000
},
{
id: 2,
name: ‘Mobile’,
price: 20000
}
])
});
});
await page.goto(‘https://example.com/products’);
await expect(page.getByText(‘Laptop’)).toBeVisible();
await expect(page.getByText(‘Mobile’)).toBeVisible();
});
Explanation:
The test intercepts the products API and returns two products. The UI is then checked to confirm that both products appear.
This is useful when the backend is unavailable or when you need predictable product data.
Q12. How do you mock a POST request?
Answer:
A POST request usually sends data to the server. We can inspect the request body and return a mock response.
test(‘Mock POST login API’, async ({ page }) => {
await page.route(‘**/api/login’, async route => {
const request = route.request();
console.log(request.method());
console.log(request.postData());
await route.fulfill({
status: 200,
contentType: ‘application/json’,
json: {
token: ‘mock-token’,
message: ‘Login successful’
}
});
});
await page.goto(‘https://example.com/login’);
await page.getByLabel(‘Username’).fill(‘testuser’);
await page.getByLabel(‘Password’).fill(‘password123’);
await page.getByRole(‘button’, {
name: ‘Login’
}).click();
});
Explanation:
The route handler captures the login request and returns a predefined response. The application can then process the response as if it came from the backend.
In a real project, use dedicated test accounts and never expose real credentials or production tokens in test code.
Q13. How do you modify request headers?
Answer:
Use route.continue() with the headers option.
await page.route(‘**/api/**’, async route => {
const headers = {
…route.request().headers(),
‘x-test-environment’: ‘automation’
};
await route.continue({
headers
});
});
This adds a custom header to matching requests.
Some browser-controlled headers cannot be overridden. For cookies, use browser context cookie APIs instead of trying to replace the browser’s cookie header.
Q14. How do you modify the request method?
Answer:
You can override the method using route.continue().
await page.route(‘**/api/users’, async route => {
await route.continue({
method: ‘POST’,
postData: {
name: ‘Test User’
}
});
});
Use this carefully because changing a method can alter application behavior and may not represent the real production workflow.
Q15. How do you intercept only POST requests?
Answer:
Check the request method inside the route handler.
await page.route(‘**/api/**’, async route => {
const request = route.request();
if (request.method() === ‘POST’) {
await route.fulfill({
status: 201,
json: {
message: ‘Record created’
}
});
} else {
await route.continue();
}
});
This mocks POST requests while allowing other HTTP methods to reach the server.
Q16. How do you wait for a specific API response?
Answer:
Use page.waitForResponse().
test(‘Wait for products response’, async ({ page }) => {
await page.goto(‘https://example.com/products’);
const responsePromise = page.waitForResponse(response =>
response.url().includes(‘/api/products’) &&
response.status() === 200
);
await page.getByRole(‘button’, {
name: ‘Refresh’
}).click();
const response = await responsePromise;
expect(response.status()).toBe(200);
});
Register the response wait before triggering the action. Otherwise, a fast response might arrive before the test starts waiting.
Q17. How do you test an API returning a 404 error?
Answer:
Mock the API with a 404 response and verify the application’s error message.
test(‘Handle product not found’, async ({ page }) => {
await page.route(‘**/api/products/999’, async route => {
await route.fulfill({
status: 404,
json: {
message: ‘Product not found’
}
});
});
await page.goto(‘https://example.com/products/999’);
await expect(
page.getByText(‘Product not found’)
).toBeVisible();
});
This validates frontend error handling without requiring the real backend to return an error.
Q18. How do you simulate a delayed API response?
Answer:
Use a delay inside the route handler.
test(‘Verify loading indicator’, async ({ page }) => {
await page.route(‘**/api/dashboard’, async route => {
await new Promise(resolve =>
setTimeout(resolve, 3000)
);
await route.fulfill({
status: 200,
json: {
message: ‘Dashboard loaded’
}
});
});
await page.goto(‘https://example.com/dashboard’);
await expect(
page.getByText(‘Loading…’)
).toBeVisible();
await expect(
page.getByText(‘Dashboard loaded’)
).toBeVisible();
});
This helps test loading indicators and delayed response handling. The example assumes the application displays a loading message while the request is pending.
Q19. What is the difference between page.route() and browserContext.route()?
Answer:
page.route() applies to requests made by a specific page.
browserContext.route() applies to requests made by pages in the browser context.
Use page.route() for page-specific testing. Use browserContext.route() when you need shared network control across multiple pages, including popup scenarios.
One important detail: page.route() does not intercept the first request of a popup page. Use context-level routing when that initial popup request must be intercepted.
Q20. What is route.fetch()?
Answer:
route.fetch() sends the original request to the server and returns the actual response to the route handler.
You can then modify that response before returning it to the browser using route.fulfill().
Example:
await page.route(‘**/api/products’, async route => {
const response = await route.fetch();
const data = await response.json();
data.push({
id: 3,
name: ‘Headphones’,
price: 3000
});
await route.fulfill({
response,
json: data
});
});
This approach is useful when you want real backend data but need to add, remove, or modify specific response values for a test.
5. Advanced Playwright Network Interception Interview Questions
Q21. What is browserContext.route()?
Answer:
browserContext.route() allows you to register network routes at the browser context level.
test(‘Context level API mocking’, async ({ context, page }) => {
await context.route(‘**/api/profile’, async route => {
await route.fulfill({
status: 200,
json: {
username: ‘automation_user’,
role: ‘admin’
}
});
});
await page.goto(‘https://example.com/profile’);
await expect(
page.getByText(‘automation_user’)
).toBeVisible();
});
This is useful when several pages in the same test need consistent mock behavior.
Q22. What is page.routeFromHAR()?
Answer:
page.routeFromHAR() allows Playwright to replay network responses recorded in a HAR file.
HAR stands for HTTP Archive. It stores information about network requests and responses.
Instead of creating every mock response manually, you can record network activity and replay it during tests.
Example:
test(‘Replay network requests from HAR’, async ({ page }) => {
await page.routeFromHAR(‘./har/products.har’, {
url: ‘**/api/**’,
notFound: ‘fallback’
});
await page.goto(‘https://example.com/products’);
await expect(
page.getByRole(‘heading’, {
name: ‘Products’
})
).toBeVisible();
});
The notFound: ‘fallback’ option allows unmatched requests to continue through the route chain. The default behavior is to abort unmatched HAR requests.
HAR replay is useful for repeatable tests and applications that depend on external services.
Q23. What is the difference between HAR replay and API mocking?
Answer:
API mocking usually means writing route handlers that return custom responses.
HAR replay uses previously recorded HTTP traffic to provide responses.
| API mocking | HAR replay |
| Responses are defined in code | Responses are stored in a HAR file |
| Easy to customize individual cases | Useful for replaying recorded traffic |
| Good for specific test scenarios | Good for repeatable network behavior |
| Requires maintaining mock data | Requires maintaining HAR files |
Both approaches help reduce dependency on live backend services.
Q24. How do you test authentication failures?
Answer:
Mock an unauthorized response and verify that the application handles it correctly.
test(‘Handle unauthorized API response’, async ({ page }) => {
await page.route(‘**/api/account’, async route => {
await route.fulfill({
status: 401,
json: {
message: ‘Unauthorized’
}
});
});
await page.goto(‘https://example.com/account’);
await expect(
page.getByText(‘Please login again’)
).toBeVisible();
});
This validates the frontend response to an expired or invalid session.
Q25. How do you test a 500 Internal Server Error?
Answer:
Use route.fulfill() to return status 500.
await page.route(‘**/api/orders’, async route => {
await route.fulfill({
status: 500,
json: {
message: ‘Internal Server Error’
}
});
});
Then verify that the application displays an appropriate error message and does not show incorrect order information.
Q26. How do you intercept requests for a particular resource type?
Answer:
Use request.resourceType().
await page.route(‘**/*’, async route => {
const type = route.request().resourceType();
if (type === ‘image’) {
await route.abort();
} else {
await route.continue();
}
});
This example blocks image requests but allows other resources.
It can be useful for performance-related experiments or tests that do not need images.
Q27. How do you remove a route after using it?
Answer:
Use page.unroute() to remove a previously registered route handler.
const handler = async (route: any) => {
await route.fulfill({
status: 200,
json: {
message: ‘Mock response’
}
});
};
await page.route(‘**/api/status’, handler);
// Perform test actions
await page.unroute(‘**/api/status’, handler);
Removing routes helps prevent unintended effects on later actions in the same page.
In normal Playwright Test usage, pages and contexts are isolated between tests, but explicit cleanup is useful in longer workflows.
Q28. Can multiple route handlers match the same request?
Answer:
Yes. Multiple registered routes can match a request.
The most recently registered matching page route takes precedence. route.continue() sends the request onward immediately, so other matching handlers are not invoked. Use route.fallback() when you want the next matching route handler in the chain to process the request.
This is important when building reusable network-mocking utilities.
Q29. Why might Playwright fail to intercept a request?
Answer:
Some common reasons are:
- The route was registered after the request started.
- The URL pattern does not match the actual request.
- A Service Worker handles the request.
- The request belongs to a popup’s initial navigation and only page-level routing was configured.
- The request is not made by the page or context being monitored.
If Service Workers interfere with routing, consider creating the context with serviceWorkers: ‘block’, when appropriate for the test.
Q30. What is the difference between network interception and API testing?
Answer:
Network interception controls requests made by a browser page. It is commonly used to test frontend behavior with mocked or modified responses.
API testing sends requests directly to an API endpoint and validates the backend response independently of the UI.
For example:
- Network interception: Mock a product API and verify that the product page displays the expected data.
- API testing: Send a GET request to the product endpoint and validate its status code and JSON response.
Both techniques are useful and can be combined in a complete automation framework.
6. Practical Project Example: Mocking an E-Commerce API
Consider an e-commerce application with a product listing page.
The frontend calls /api/products to retrieve product details. During automation, the backend may be unavailable or the product data may change frequently.
We can use network interception to return stable test data.
import { test, expect } from ‘@playwright/test’;
test(‘Verify mocked product listing’, async ({ page }) => {
await page.route(‘**/api/products’, async route => {
await route.fulfill({
status: 200,
contentType: ‘application/json’,
json: [
{
id: 101,
name: ‘Laptop’,
price: 50000,
availability: ‘In Stock’
},
{
id: 102,
name: ‘Keyboard’,
price: 1500,
availability: ‘Out of Stock’
}
]
});
});
await page.goto(‘https://example.com/products’);
await expect(page.getByText(‘Laptop’)).toBeVisible();
await expect(page.getByText(‘50000’)).toBeVisible();
await expect(page.getByText(‘Keyboard’)).toBeVisible();
await expect(page.getByText(‘Out of Stock’)).toBeVisible();
});
What does this project demonstrate?
- Intercepting a GET request.
- Returning custom JSON.
- Testing product information.
- Validating frontend behavior.
- Reducing dependency on backend data.
In an actual project, replace the example URL and UI selectors with the application’s real values.
7. Testing Network Failures and Error Scenarios
A strong QA automation engineer should test more than successful API responses.
Important network scenarios include:
| Scenario | Expected application behavior |
| 400 Bad Request | Display validation or request error |
| 401 Unauthorized | Ask the user to authenticate |
| 403 Forbidden | Display an access-denied message |
| 404 Not Found | Display a not-found message |
| 500 Server Error | Display a general server error |
| Delayed response | Display a loading indicator |
| Aborted request | Display an appropriate failure state |
| Empty response data | Display an empty-state message |
For example, to test an empty product list:
await page.route(‘**/api/products’, async route => {
await route.fulfill({
status: 200,
json: []
});
});
await page.goto(‘https://example.com/products’);
await expect(
page.getByText(‘No products available’)
).toBeVisible();
This verifies that the application handles an empty API response correctly.
8. Integrating Network Interception into Regression Testing and CI/CD
Network interception can make regression testing more predictable, especially when an application depends on external services.
A practical regression strategy can divide tests into three groups.
Group 1: UI tests with mocked APIs
Use mocked responses to validate frontend behavior, error messages, empty states, and loading indicators.
Group 2: Integration tests with real APIs
Use actual backend services to verify that the frontend and backend communicate correctly.
Group 3: Independent API tests
Use Playwright’s API testing capabilities to validate endpoints, status codes, response bodies, and authentication.
For continuous integration, configure the Playwright test runner to execute these suites in a controlled environment.
Example GitHub Actions workflow:
name: Playwright Network Tests
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
– name: Checkout code
uses: actions/checkout@v4
– name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
– name: Install dependencies
run: npm ci
– name: Install Playwright browsers
run: npx playwright install –with-deps
– name: Run tests
run: npx playwright test
– name: Upload test report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
Important CI/CD practices:
- Keep mock data version-controlled.
- Avoid using production credentials in test files.
- Use environment variables for environment-specific configuration.
- Separate mocked UI tests from real backend integration tests.
- Capture traces and reports for failed tests.
- Keep tests independent so they can run in parallel.
- Review mock responses when API contracts change.
Network mocking should not replace all real API testing. A test suite that only uses mocked responses cannot prove that the real backend integration works.
9. Common Playwright Network Interception Errors and Troubleshooting
Error 1: Route handler is not triggered
Possible reason: The URL pattern does not match the request.
Solution: Log the actual URL and check the route pattern.
page.on(‘request’, request => {
console.log(request.url());
});
Error 2: API response is not mocked
Possible reason: The request started before the route was registered.
Solution: Register the route before navigating to the page or performing the action that triggers the request.
Error 3: Test fails when using route.fulfill()
Possible reason: The mocked response does not match the format expected by the frontend.
Solution: Check the response status, JSON structure, content type, and required fields.
Error 4: Network events are missing
Possible reason: A Service Worker may be handling the request.
Solution: Consider disabling Service Workers in the test context:
const context = await browser.newContext({
serviceWorkers: ‘block’
});
Use this only when blocking Service Workers is appropriate for the test. If Service Worker behavior itself is under test, do not disable it.
Error 5: Request is intercepted but the test hangs
Possible reason: A matching route handler did not call continue(), fulfill(), abort(), or another appropriate route-handling method.
Solution: Ensure every route handler completes the request.
Error 6: HAR replay does not return the expected response
Possible reason: The request URL or recorded data does not match the actual application request.
Solution: Verify the HAR file, request URL, and replay options. Also check whether a Service Worker is intercepting the request.
10. Best Practices for Playwright Network Interception
Follow these practices when implementing network interception in a professional automation framework.
- Register routes before triggering the related network request.
- Use specific URL patterns instead of intercepting every request unnecessarily.
- Keep mock response data separate from test logic.
- Use meaningful test data that represents real application conditions.
- Test both successful and unsuccessful API responses.
- Use page.waitForResponse() when a test needs to verify a specific response.
- Use browserContext.route() when multiple pages need shared routing.
- Use HAR replay when recorded network traffic provides a useful, maintainable test fixture.
- Avoid mocking every API in integration and end-to-end tests.
- Keep route handlers readable and reusable.
- Avoid storing passwords, tokens, or sensitive personal data in HAR files.
- Review mocks when backend API contracts change.
11. Scenario-Based Playwright Network Interception Interview Questions
Scenario 1: Backend API is unavailable. How would you test the frontend?
Sample Answer:
I would use page.route() to intercept the required API request and return a predefined response using route.fulfill().
Then I would validate whether the frontend displays the expected data.
I would also test error and empty-state responses to confirm that the application handles different conditions correctly.
Scenario 2: The API returns a 500 error. How would you validate the UI?
Sample Answer:
I would mock the API with status 500 and a suitable error response. Then I would verify that the application displays a meaningful error message and does not display incorrect or stale information.
Scenario 3: An API takes five seconds to respond. How would you test the loading indicator?
Sample Answer:
I would introduce a controlled delay inside the route handler. While the response is pending, I would verify that the loading indicator is visible. After fulfilling the request, I would verify that the loading indicator disappears and the expected content is displayed.
Scenario 4: A third-party payment API is unavailable. How would you continue testing checkout?
Sample Answer:
I would mock the payment API for frontend workflow tests. I would cover successful payment, declined payment, timeout, and invalid payment responses.
However, I would keep separate integration tests against a payment sandbox to validate the real service interaction.
Scenario 5: Your route handler is not intercepting a popup request. What would you do?
Sample Answer:
I would check whether the request is the popup’s initial navigation. Page-level routing does not intercept that first popup request. I would use browserContext.route() so the route is registered at the context level.
Scenario 6: How would you test a user session that has expired?
Sample Answer:
I would mock the protected API response with status 401. Then I would verify that the application redirects the user to the login page or displays an appropriate session-expired message.
Scenario 7: Your mocked test passes, but the real API integration fails. What does this indicate?
Sample Answer:
It may indicate a mismatch between the mock response and the actual API contract, an authentication issue, incorrect request data, or a backend integration problem.
I would compare the real request and response with the mock data and add or update integration tests.
12. How to Prepare for Playwright Network Interception Interviews
Candidates should prepare according to their experience level.
For freshers:
Focus on:
- What network interception means.
- The page.route() method.
- route.fulfill(), route.continue(), and route.abort().
- Basic GET request mocking.
- Monitoring request and response events.
- Testing 404 and 500 responses.
For candidates with 1–3 years of experience:
Focus on:
- GET and POST interception.
- Request headers and payloads.
- Response validation.
- Delayed API responses.
- Authentication failures.
- HAR replay.
- Combining API and UI tests.
- CI/CD execution.
For experienced QA engineers and SDETs:
Focus on:
- Reusable network-mocking utilities.
- Context-level routing.
- Route handler precedence and fallback.
- Service Worker limitations.
- Test-data management.
- Mock versus integration testing strategy.
- Regression suite design.
- Debugging intermittent network failures.
Downloadable Playwright Network Interception Starter Project
A useful portfolio project should demonstrate:
playwright-network-project/
│
├── tests/
│ ├── get-api-mock.spec.ts
│ ├── post-api-mock.spec.ts
│ ├── network-error.spec.ts
│ ├── delayed-response.spec.ts
│ └── authentication.spec.ts
│
├── test-data/
│ ├── products.json
│ └── users.json
│
├── utils/
│ └── network-mocks.ts
│
├── playwright.config.ts
└── package.json
Build the project with TypeScript and Playwright Test. Add tests for successful responses, server errors, delayed responses, and failed requests. Include a README with installation steps and example commands.
This gives interviewers evidence that you can apply network interception rather than only explain its definition.
13. Frequently Asked Questions About Playwright Network Interception
What are the benefits of Playwright network interception?
It allows QA engineers to mock API responses, modify HTTP requests, simulate network failures, test error handling, reduce external dependencies, and improve test stability.
How do I get started with Playwright network interception?
Install Playwright Test, create a TypeScript test, register a route using page.route(), and return a mock response using route.fulfill().
Start with a simple GET request before moving to POST requests, error scenarios, and HAR replay.
What is the difference between page.route() and route.fulfill()?
page.route() registers a handler for matching requests. route.fulfill() is an action inside that handler that returns a custom response.
Can Playwright intercept POST requests?
Yes. You can inspect POST request data using route.request().postData() and return a mock response using route.fulfill().
Can Playwright mock a 500 error?
Yes. Use route.fulfill({ status: 500, … }) and verify that the frontend handles the error correctly.
Is network interception the same as API testing?
No. Network interception controls browser-generated requests. API testing sends requests directly to API endpoints and validates their responses independently of the browser UI.
Does network interception work in CI/CD?
Yes. Playwright network routing can run in CI/CD pipelines just like other Playwright tests, provided the required browser and test dependencies are installed.
Should we mock every API in regression testing?
No. Mocking is useful for predictable UI tests, but real API integration tests are also necessary to validate actual frontend-backend communication.
