playwright

playwright is a cursor rule for Cursor from antdigital-ai/agentic-ui. It costs 2,559 tokens per session, scanned A, original, MIT.

Rules for writing reliable Playwright browser tests. Playwright is a tool that drives a real browser to check complete user journeys, such as signing in or completing checkout.

In plain words
What is it for?
Use them to organise end-to-end tests, name test files, structure reusable test setup and page objects, and reduce flaky results.
Why use it?
They address common test failures caused by timing races, changing page structure, network problems, and unstable external services.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use them to organise end-to-end tests, name test files, structure reusable test setup and page objects, and reduce flaky results.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/antdigital-ai/agentic-ui/playwright
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/antdigital-ai/agentic-ui

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for playwright

README.md
[![agentmods](https://agentmods.dev/badge/rules/antdigital-ai/agentic-ui/playwright/github.svg)](https://agentmods.dev/rules/antdigital-ai/agentic-ui/playwright)
Your own site
<a href="https://agentmods.dev/rules/antdigital-ai/agentic-ui/playwright"><img src="https://agentmods.dev/badge/rules/antdigital-ai/agentic-ui/playwright/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for playwright

Your own site · 80×15
<a href="https://agentmods.dev/rules/antdigital-ai/agentic-ui/playwright"><img src="https://agentmods.dev/badge/rules/antdigital-ai/agentic-ui/playwright.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 2,559 This file is loaded in full into every session.
When invoked 2,559 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.02559 $0.02559
Opus 5.5 $0.01024 $0.01024
Sonnet 5.5 $0.00512 $0.00512
Haiku 4.5 $0.00256 $0.00256

Measured 1mo ago against content hash b3ee73bf5cec, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

playwright scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/playwright.mdc · 236 lines

How it starts

The opening of the file, as written. The whole thing — 236 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Playwright 自动化测试编写规范:构建高稳定性(Flaky-Free)的测试体系

1. 核心原则:为何测试会失败?

在制定规范前,需明确 Playwright 测试失败的三大核心根因。编写"高成功率"测试的本质,就是通过规范消除这三个变量:

竞态条件 (Race Conditions)

脚本执行速度快于页面渲染速度(如点击了尚未绑定事件的按钮)。

DOM 易变性 (DOM Volatility)

页面结构或样式变化导致选择器失效。

环境不确定性 (Environmental Flakiness)

网络延迟、API 500 错误或第三方服务宕机。

本规范将围绕**"确定性执行 (Deterministic Execution)"**这一目标展开。

2. 目录结构与命名规范 (TypeScript)

采用**领域驱动(Domain-Driven)**结构,将测试与业务逻辑解耦。推荐使用 TypeScript 以获得强类型支持,这直接关联到代码维护的稳定性。

2.1 推荐目录结构

tests/
├── e2e/
│   ├── auth.setup.ts            # 全局认证设置(生成 storageState)
│   ├── checkout/                # 业务模块目录
│   │   ├── guest-checkout.spec.ts
│   │   └── payment-flow.spec.ts
│   └── dashboard/
│       └── analytics.spec.ts
├── fixtures/                    # 自定义测试夹具 (Dependency Injection)
│   ├── db-fixture.ts            # 数据库操作封装
│   └── page-fixture.ts          # Page Object 自动注入
├── pages/                       # Page Object Models (POM)
│   ├── CheckoutPage.ts
│   └── components/              # 可复用组件 (如 DatePicker, Modal)
├── test-data/                   # 静态测试数据
├── playwright.config.ts         # 全局配置
└── .eslintrc.json               # 强制代码规范配置

2.2 命名规范

  • 文件命名:使用 kebab-case,后缀为 .spec.ts。例如 user-login.spec.ts。
  • 类命名 (POM):使用 PascalCase。例如 LoginPage, ShoppingCartPage。
  • 测试标题:必须表达业务价值而非操作细节。
    • ❌ test('click button and check div')
    • ✅ test('should display order confirmation after successful payment')

3. 高稳定性选择器策略 (Selector Strategy)

稳定性黄金法则:测试应当像用户一样通过"视觉"和"内容"来寻找元素,严禁依赖页面内部实现(CSS 类名、XPath)。

3.1 优先级金字塔

请严格按照以下顺序选用 Locator:

page.getByRole() (最高优先级)

理由:它是最稳定的选择器。它模拟用户和辅助技术(Screen Readers)的交互。如果页面样式变了但功能没变(例如"登录"按钮变成了一个图标但 ARIA 角色还是 button),测试依然通过。

示例:

await page.getByRole('button', { name: 'Submit' }).click();
page.getByText()

理由:适用于非交互性文本内容的验证。

示例:

await expect(page.getByText('Welcome, User')).toBeVisible();
page.getByTestId() (特定场景)

理由:当元素没有任何语义(如纯 div 容器)且必须定位时使用。需在前端代码中添加 data-testid 属性。

Read the full file on GitHub · 236 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 236 lines · 2,559 tokens per session scan A b3ee73bf5cec

Subscribe to this mod's changes

playwright is a cursor rule published in the GitHub repository antdigital-ai/agentic-ui (233 stars, last pushed 4d ago), licensed MIT. It adds 2,559 tokens to every session, about $0.0102 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.