使用方法
- 复制安装命令,在自己的智能体环境安装前先检查源码包。
- 从原始文档核对所需工具、凭据和支持的宿主。
- 说明输入材料与期望交付物,并对照来源检查输出。
npx skills add https://github.com/spencerpauly/awesome-cursor-skills --skill recording-browser-flow-as-test开始前需了解
- 安装不包含模型订阅、API 额度或访问文件的权限。
- 仓库星数和安装量反映活跃情况,不等于独立质量或安全测试。
按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。
Recording Browser Flow as Playwright Test
Use the browser MCP as a recorder: every navigation, click, fill, and keypress becomes a row in a script. The agent then translates that trace into a Playwright test file in the repo (or a snippet to paste into an existing spec).
This is Cursor-native because it combines browser_snapshot (refs + roles + names) with structured actions — not a separate recorder extension.
Prerequisites
- Target app reachable (e.g. dev server running); use
finding-dev-server-urlif needed. - Repo has or will have Playwright installed (
@playwright/test). If not, add it withadding-e2e-testsor the project’s standard setup.
Recording workflow
1. Define the flow
One sentence scope, e.g. “Log in, open Settings, toggle dark mode, save.”
2. For each step, in order
- `browser_snapshot` — get the accessibility tree and element refs.
- Choose the smallest interaction:
browser_clickwith ref from snapshot (not coordinate clicks unless required).browser_fillorbrowser_typefor inputs.browser_select_optionfor selects.browser_navigatefor full URL changes.
- Log the step in a structured list the main agent keeps:
- Step number
- Action verb (
navigate,click,fill,press,select) - Locator strategy for Playwright — prefer:
getByRole('button', { name: '...' })getByLabel('...')getByPlaceholder('...')getByTestId('...')if the app uses test IDs- Value (for fills), URL (for navigates)
- Optional: short assertion (“expect URL to contain
/settings”)
- After actions that change the DOM or navigate, take a new
browser_snapshotbefore the next interaction.
- If the flow must wait for async content, use
browser_wait_foror short incremental waits percursor-ide-browserguidance — then snapshot again.
3. Add assertions
From the final snapshot and URL, add at least:
expect(page).toHaveURL(...)or URL fragment check- One visible outcome: text, role, or test id
4. Generate Playwright output
Emit a test file, e.g. tests/recorded/<flow-name>.spec.ts, containing:
test.describeandtest('...', async ({ page }) => { ... })- Steps as
await page.goto(...),await page.getByRole(...).click(), etc. - No raw snapshot refs in the final file — they are session-specific.
5. Run and harden
npx playwright test tests/recorded/<flow-name>.spec.tsFix flakiness: prefer expect(locator).toBeVisible() before clicks, use toPass() retries for async lists, avoid arbitrary waitForTimeout except as last resort.
Tips
- Stable selectors: roles and accessible names beat CSS from devtools. Add
data-testidin app code if names are ambiguous. - Auth: if the flow needs login, use env vars for test credentials or Playwright
storageState— never commit secrets. - Parallel runs: ensure test data does not collide with other tests.
When not to use
- Flows that require manual 2FA, captchas, or email links — stop and ask the user for a test bypass or mock.



