Skip to content

Commit c759cb8

Browse files
committed
fix: strengthen web.md - bare button pitfall12, attribute source verification, flow checklist scan
1 parent ba13329 commit c759cb8

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

  • extension/templates/platforms

extension/templates/platforms/web.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ A React component `<LoginForm>` does NOT generate a `.LoginForm` CSS class. Chec
9292
Tailwind classes like `.flex`, `.mt-4`, `.bg-blue-600` match dozens of elements. Use semantic attributes (`#id`, `[title]`, `[data-testid]`, `[placeholder]`) instead.
9393

9494
**Tailwind selector strategy:**
95-
1. Prefer `id`, `name`, `title`, `placeholder`, `data-testid`, `type` attributes
95+
1. Prefer `id`, `name`, `title`, `placeholder`, `data-testid`, `type` attributes**only if the attribute actually exists in source code** (open the file and verify!)
9696
2. Find a **semantic class** unique to the element (e.g. `.submit-btn`, NOT `.flex`)
9797
3. If only Tailwind classes exist, use context combo: `.parent-class button[title='xxx']`
9898
4. Last resort: ask the developer to add `data-testid` or `id`
@@ -112,6 +112,26 @@ Custom components like `<Select>`, `<Modal>`, `<DatePicker>` do NOT appear as CS
112112
-`name:xxx` — desktop-only selector, NOT for Web
113113
- ❌ Bare tag selectors (`div`, `span`, `button` with no attributes)
114114

115+
**Pitfall 12 Bare `button` selector (CRITICAL):**
116+
Writing `"target": "button"` with no attributes is forbidden. Playwright matches the **first** button in the DOM, which may be a hidden button, an icon button, or the wrong button entirely. This is the most common cause of wrong-element clicks that appear to succeed (no error) but operate the wrong control.
117+
118+
| ❌ Forbidden | Why wrong | ✅ Correct approach |
119+
|---|---|---|
120+
| `"target": "button"` | Matches ANY button, usually wrong one | Read source: use `button[type='submit']`, `#btn-register`, `.btn-life-book` etc. |
121+
| `"target": "span"` | Matches ANY span | Use `#id` or semantic class |
122+
123+
> **Iron rule:** Every `click` target MUST have at least one attribute constraint. Bare tag selectors (`button`, `a`, `div`, `span`) are FORBIDDEN without exception.
124+
125+
### ⚠️ Attribute Selectors Require Source Verification
126+
127+
When using `[title='xxx']`, `[aria-label='xxx']`, `[data-testid='xxx']`, `[placeholder='xxx']`:
128+
129+
1. **MUST open the source file first** and confirm the attribute exists on that element
130+
2. **NEVER guess attribute values** from the element's visible text or purpose
131+
3. `[title]` is a tooltip attribute — many icon buttons in React/Vue apps do NOT have it
132+
133+
> Typical mistake: seeing a "财务报表" navigation button and writing `button[title='财务报表']` — but the button has no `title` attribute in source code → 10s timeout on every run.
134+
115135
**Pitfall 7 `:contains()` causes SyntaxError:**
116136
`:contains()` is jQuery-only syntax. Playwright and modern CSS engines do NOT support it. Any selector with `:contains()` throws `SyntaxError: Failed to execute` and aborts the entire scenario. Use `#id`, `.class`, or `[attribute]` selectors instead.
117137

@@ -281,6 +301,7 @@ Do NOT put multiple independent dialog interactions in one scenario. Each distin
281301
**Check 1 Flow decision:** For each page with 2 scenarios that ALL require login first:
282302
- YES that page MUST have `"flow": true` AND non-first scenarios MUST NOT contain login steps
283303
- NO no flow needed (each scenario independently logs in)
304+
- **Scan every non-first scenario in flow pages: if it contains `fill username` / `fill password` / `click login`, DELETE those steps immediately — they belong only in the first scenario**
284305

285306
**Check 2 Assert coverage:** For every scenario, does it have at least one `assert_text` step?
286307
- Screenshot alone is NOT sufficient must have text assertion

0 commit comments

Comments
 (0)