pw-network-mocker
Designs Playwright route interception and mocking. Use when an SDET says "mock this API", "stub the /orders response", "force a 500 error state", "make this test deterministic without the backend", or "intercept network calls". Produces page.route / fulfill handlers to stub responses, simulate errors, and remove backend flakiness — a draft the engineer wires in and runs.
- License 许可
- MIT
- 最近更新
- 2026-07-15
- Stars
- ★ 4
- Forks
- 8
01 前言 Front Matter
- name
- pw-network-mocker
- license
- MIT
- metadata
- { "pack": "playwright", "author": "TheTestingAcademy", "version": "1.0.0" }
- description
- Designs Playwright route interception and mocking. Use when an SDET says "mock this API", "stub the /orders response", "force a 500 error state", "make this test deterministic without the backend", or "intercept network calls". Produces page.route / fulfill handlers to stub responses, simulate errors, and remove backend flakiness — a draft the engineer wires in and runs.
03 SKILL.md 正文
PW Network Mocker
You draft route mocks the engineer must wire in and verify — never a proven setup. You make tests deterministic and let them exercise states a real backend won't produce on demand.
When to use
- A test depends on a slow, flaky, or unavailable backend.
- You need to force an error/empty/loading state the real API rarely returns.
- Someone says "mock/stub/intercept this request".
Workflow
- Identify the exact request — method + URL pattern (glob or regex). Match narrowly so you don't accidentally stub unrelated calls.
- Decide mock vs. modify:
route.fulfill()to return a canned response;route.fetch()then fulfill to tweak a real response;route.abort()to simulate a network failure. Register the route before the navigation/action that triggers it. - Author realistic fixtures — status, headers, and a body matching the real schema. Keep payloads in a fixtures file, not inline, when reused.
- Cover the states that matter — success, empty list, 4xx/5xx, and slow/aborted — each as its own deterministic test.
- Assert on the UI behavior, and note which fields you assumed vs. confirmed.
Output shape
import { test, expect } from '@playwright/test';
test('shows an error banner when orders API fails', async ({ page }) => {
await page.route('**/api/orders', (route) =>
route.fulfill({ status: 500, contentType: 'application/json',
body: JSON.stringify({ error: 'internal' }) }));
await page.goto('/orders');
await expect(page.getByTestId('orders-error')).toBeVisible();
});
test('renders empty state', async ({ page }) => {
await page.route('**/api/orders', (route) =>
route.fulfill({ status: 200, body: JSON.stringify([]) }));
await page.goto('/orders');
await expect(page.getByText('No orders yet')).toBeVisible();
});
Guardrails
- This is a draft the engineer must run — never assume the request URL, method, or response schema; confirm against the real network tab / contract.
- Never fabricate a response shape that diverges from production — a passing mock against a wrong schema is a false green.
- Register routes before the triggering action, and scope URL patterns tightly.
- No
waitForTimeoutto "wait for the mock"; assert on the resulting UI state.
04 同仓库更多 Skills
se-wait-fixer
Scans Selenium Java code for Thread.sleep and for implicit+explicit wait mixing, then replaces them with WebDriverWait/ExpectedConditions or FluentWait to fix synchronization. Use when an SDET says "remove Thread.sleep from my tests", "fix the flaky waits", "my implicit and explicit waits conflict", or pastes code full of hard sleeps. Produces refactors the engineer must run and confirm.
se-test-generator
Generates a runnable Selenium 4 + TestNG test in Java from a plain-language scenario, using explicit waits and stable locators. Use when an SDET says "write a Selenium test for login", "generate a TestNG test for the checkout flow", "automate this scenario in Selenium", or pastes Gherkin/steps and wants Java WebDriver code. Produces a draft test the engineer must review and run.
se-report-integrator
Integrates reporting (Allure or ExtentReports) into a Selenium + TestNG suite with listeners, screenshot-on-failure, and step logging. Use when an SDET says "add Allure to my tests", "set up ExtentReports", "capture a screenshot on failure", "add a TestNG listener for reporting", or wants readable run reports. Produces listener and config code the engineer must run to generate a report.
se-page-object-builder
Builds a Page Object Model class in Java (PageFactory @FindBy or explicit locators) with action methods and a WebDriverWait for a given page. Use when an SDET says "create a page object for the login page", "build a POM class", "refactor these locators into a page object", or pastes a page's fields and wants a reusable POM. Produces a draft class the engineer must review and run.
se-locator-strategist
Recommends and repairs Selenium locator strategy — replaces brittle absolute XPath with By.id, By.cssSelector, or Selenium 4 relative locators, and explains the trade-offs. Use when an SDET says "this XPath keeps breaking", "make this locator more stable", "why is my locator flaky", "convert this XPath to CSS", or pastes selectors to harden. Produces proposals the engineer must verify in the DOM.
se-grid-configurator
Configures Selenium Grid 4 (hub-and-node or standalone, including Docker) and wires RemoteWebDriver for parallel and distributed runs. Use when an SDET says "set up Selenium Grid", "run my tests on a remote grid", "dockerize Selenium Grid 4", "point my tests at RemoteWebDriver", or wants parallel execution across nodes. Produces config and code the engineer must run and validate in their environment.