跳到正文
cccskills
免费在 GitHub 公开

playwright-network-mocking

Playwright workflows for deterministic third-party responses using page.route().

中文简介正在准备中。当前显示原文说明。

集成工具Playwright
查看安装方法

包含的文件(1)

  • SKILL.md2.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Playwright Network Mocking

Overview

Use this skill when a test depends on a slow, unreliable, or external service and you need deterministic responses without hitting the real provider. It lets you isolate the boundary that matters while keeping the rest of the application real.

Do not use this skill when the real third-party integration is the feature under test, or when the app is already local and deterministic without request interception.

When to Use

  • When a test depends on an unreliable or slow external API.
  • When you need deterministic responses for billing, email, auth, analytics, or similar services.
  • When you want to mock the minimum necessary surface area and leave the rest of the app untouched.

When Not to Use

  • When the test must validate a real provider integration end to end.
  • When the login UI is the feature under test.
  • When you are diagnosing a flaky test and should start with playwright-debugging instead.

Network Interception

Use page.route() to replace external responses with deterministic data before the page makes the request.

import { test, expect } from '@playwright/test';

test('shows premium dashboard when billing is active', async ({ page }) => {
  await page.route('**/api/v1/billing/status', async route => {
    await route.fulfill({
      status: 200,
      json: {
        subscription: 'active',
        plan: 'premium',
      },
    });
  });

  await page.goto('/dashboard');

  await expect(page.getByRole('heading', { name: 'Welcome to Premium' })).toBeVisible();
});

Intercept only the unstable boundary and leave the rest of the application real. If the code under test makes several external calls, mock the minimum necessary surface area.

Prefer page.route() when the response is part of the behavior under test and must be controlled from the browser context. If you need broader, suite-wide control, consider a fixture or a backend test double instead of scattering route handlers through individual tests.

Verification

Verify the intercepted request produces the expected UI and that the real service is not required for the test to pass.

Typical checks:

npx playwright test tests/dashboard.spec.ts

Use trace viewer or UI mode to confirm the mocked response is the one the app consumed.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Playwright workflows for authenticated browser state reuse through storageState and setup projects.

中文简介正在准备中。当前显示原文说明。

hzijad/playwright-agent-skills92026年7月16日 更新

Conducts rigorous authoring and review of Playwright E2E tests. Enforces accessibility-first locators, web-first assertions, strict isolation, and DAMP architecture. Use when generating, refactoring, or reviewing any Playwright test code.

中文简介正在准备中。当前显示原文说明。

hzijad/playwright-agent-skills92026年7月16日 更新

Diagnostic Playwright workflows for flaky or failing tests, including trace analysis, UI mode, and state isolation.

中文简介正在准备中。当前显示原文说明。

hzijad/playwright-agent-skills92026年7月16日 更新

查看 hzijad 的全部技能

报告此技能的问题