@sun-asterisk/sungen 2.2.3 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/cli/commands/update.d.ts +3 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +21 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/index.js +3 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/generators/gherkin-parser/index.d.ts +2 -0
- package/dist/generators/gherkin-parser/index.d.ts.map +1 -1
- package/dist/generators/gherkin-parser/index.js +16 -2
- package/dist/generators/gherkin-parser/index.js.map +1 -1
- package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/attribute-assertion.hbs +3 -0
- package/dist/generators/test-generator/adapters/playwright/templates/steps/partials/locator-base.hbs +12 -1
- package/dist/generators/test-generator/adapters/playwright/templates/steps/partials/locator.hbs +12 -1
- package/dist/generators/test-generator/patterns/assertion-patterns.d.ts.map +1 -1
- package/dist/generators/test-generator/patterns/assertion-patterns.js +12 -0
- package/dist/generators/test-generator/patterns/assertion-patterns.js.map +1 -1
- package/dist/generators/test-generator/patterns/index.d.ts +9 -0
- package/dist/generators/test-generator/patterns/index.d.ts.map +1 -1
- package/dist/generators/test-generator/patterns/index.js +32 -0
- package/dist/generators/test-generator/patterns/index.js.map +1 -1
- package/dist/generators/test-generator/patterns/interaction-patterns.d.ts.map +1 -1
- package/dist/generators/test-generator/patterns/interaction-patterns.js +0 -13
- package/dist/generators/test-generator/patterns/interaction-patterns.js.map +1 -1
- package/dist/generators/test-generator/patterns/table-patterns.d.ts.map +1 -1
- package/dist/generators/test-generator/patterns/table-patterns.js +8 -5
- package/dist/generators/test-generator/patterns/table-patterns.js.map +1 -1
- package/dist/orchestrator/ai-rules-updater.d.ts +13 -0
- package/dist/orchestrator/ai-rules-updater.d.ts.map +1 -0
- package/dist/orchestrator/ai-rules-updater.js +159 -0
- package/dist/orchestrator/ai-rules-updater.js.map +1 -0
- package/dist/orchestrator/project-initializer.d.ts.map +1 -1
- package/dist/orchestrator/project-initializer.js +2 -27
- package/dist/orchestrator/project-initializer.js.map +1 -1
- package/dist/orchestrator/screen-manager.d.ts +1 -0
- package/dist/orchestrator/screen-manager.d.ts.map +1 -1
- package/dist/orchestrator/screen-manager.js +70 -3
- package/dist/orchestrator/screen-manager.js.map +1 -1
- package/dist/orchestrator/templates/ai-instructions/claude-cmd-add-screen.md +18 -9
- package/dist/orchestrator/templates/ai-instructions/claude-cmd-make-tc.md +12 -4
- package/dist/orchestrator/templates/ai-instructions/claude-cmd-make-test.md +9 -11
- package/dist/orchestrator/templates/ai-instructions/claude-skill-gherkin-review.md +228 -0
- package/dist/orchestrator/templates/ai-instructions/claude-skill-gherkin-syntax.md +30 -11
- package/dist/orchestrator/templates/ai-instructions/claude-skill-selector-fix.md +91 -25
- package/dist/orchestrator/templates/ai-instructions/claude-skill-tc-generation.md +92 -71
- package/dist/orchestrator/templates/ai-instructions/copilot-cmd-add-screen.md +13 -5
- package/dist/orchestrator/templates/ai-instructions/copilot-cmd-make-tc.md +13 -4
- package/dist/orchestrator/templates/ai-instructions/copilot-cmd-make-test.md +9 -11
- package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-gherkin-review.md +228 -0
- package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-gherkin-syntax.md +30 -11
- package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-selector-fix.md +72 -31
- package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-tc-generation.md +92 -72
- package/dist/orchestrator/templates/readme.md +13 -8
- package/package.json +1 -1
- package/src/cli/commands/update.ts +18 -0
- package/src/cli/index.ts +3 -1
- package/src/generators/gherkin-parser/index.ts +19 -2
- package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/attribute-assertion.hbs +3 -0
- package/src/generators/test-generator/adapters/playwright/templates/steps/partials/locator-base.hbs +12 -1
- package/src/generators/test-generator/adapters/playwright/templates/steps/partials/locator.hbs +12 -1
- package/src/generators/test-generator/patterns/assertion-patterns.ts +13 -0
- package/src/generators/test-generator/patterns/index.ts +41 -0
- package/src/generators/test-generator/patterns/interaction-patterns.ts +0 -14
- package/src/generators/test-generator/patterns/table-patterns.ts +8 -5
- package/src/orchestrator/ai-rules-updater.ts +141 -0
- package/src/orchestrator/project-initializer.ts +2 -32
- package/src/orchestrator/screen-manager.ts +72 -3
- package/src/orchestrator/templates/ai-instructions/claude-cmd-add-screen.md +18 -9
- package/src/orchestrator/templates/ai-instructions/claude-cmd-make-tc.md +12 -4
- package/src/orchestrator/templates/ai-instructions/claude-cmd-make-test.md +9 -11
- package/src/orchestrator/templates/ai-instructions/claude-skill-gherkin-review.md +228 -0
- package/src/orchestrator/templates/ai-instructions/claude-skill-gherkin-syntax.md +30 -11
- package/src/orchestrator/templates/ai-instructions/claude-skill-selector-fix.md +91 -25
- package/src/orchestrator/templates/ai-instructions/claude-skill-tc-generation.md +92 -71
- package/src/orchestrator/templates/ai-instructions/copilot-cmd-add-screen.md +13 -5
- package/src/orchestrator/templates/ai-instructions/copilot-cmd-make-tc.md +13 -4
- package/src/orchestrator/templates/ai-instructions/copilot-cmd-make-test.md +9 -11
- package/src/orchestrator/templates/ai-instructions/github-skill-sungen-gherkin-review.md +228 -0
- package/src/orchestrator/templates/ai-instructions/github-skill-sungen-gherkin-syntax.md +30 -11
- package/src/orchestrator/templates/ai-instructions/github-skill-sungen-selector-fix.md +72 -31
- package/src/orchestrator/templates/ai-instructions/github-skill-sungen-tc-generation.md +92 -72
- package/src/orchestrator/templates/readme.md +13 -8
- package/docs/gherkin standards/gherkin-core-standard.md +0 -431
- package/docs/gherkin standards/gherkin-core-standard.vi.md +0 -399
- package/docs/gherkin-dictionary.md +0 -1126
- package/docs/makeauth.md +0 -225
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sungen-gherkin-review
|
|
3
|
+
description: 'Quality review checklist for Gherkin test cases — assertion quality rules, action-result coherence, and 9-point checklist. Auto-loaded during self-review step of make-tc.'
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Assertion Quality Rules
|
|
8
|
+
|
|
9
|
+
**CRITICAL** — these rules prevent shallow, low-value test cases:
|
|
10
|
+
|
|
11
|
+
1. **NEVER use `is visible`** — `User see [T] type` already asserts visibility. Writing `is visible` is redundant noise. Only use `is hidden` to assert something is NOT shown.
|
|
12
|
+
2. **Group related assertions** — one scenario can have 3-7 `Then/And` steps. Don't waste a whole scenario on one element. Group elements that verify the same concern.
|
|
13
|
+
3. **Assert content, not just existence** — verify values, text, states, not just "it's there". Every assertion should answer: what EXACTLY should the user see? Add `with {{value}}` or `is state` whenever the expected content/state is known.
|
|
14
|
+
- `User see [Title] heading with {{page_title}}` — verify text
|
|
15
|
+
- `User see [Email] field with {{default_email}}` — verify default value
|
|
16
|
+
- `User see [Submit] button is disabled` — verify state
|
|
17
|
+
- `User see [Error] message with {{error_text}}` — verify exact error
|
|
18
|
+
4. **Don't assume element roles** — never guess the element type (`button`, `option`, `link`, etc.) based on the label or expected behavior. Developers create custom components that don't match standard HTML roles (e.g., a `<div>` styled as a button, a custom dropdown built from `<li>` elements). Always use the **live-page selector scan result** or the selector YAML to determine the correct type. If you haven't scanned the page and the type is uncertain, use a generic type (`text`) or mark the scenario `@manual` until selectors are confirmed.
|
|
19
|
+
|
|
20
|
+
**Bad** (shallow — just checks existence):
|
|
21
|
+
```gherkin
|
|
22
|
+
Scenario: VP-UI-001 Email field is visible
|
|
23
|
+
Given User is on [Login] page
|
|
24
|
+
Then User see [Email] field is visible
|
|
25
|
+
|
|
26
|
+
Scenario: VP-UI-002 Password field is visible
|
|
27
|
+
Given User is on [Login] page
|
|
28
|
+
Then User see [Password] field is visible
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Good** (rich — verifies content, states, groups related checks):
|
|
32
|
+
```gherkin
|
|
33
|
+
Scenario: VP-UI-001 Login form displays all fields with correct defaults
|
|
34
|
+
Given User is on [Login] page
|
|
35
|
+
Then User see [Login] heading with {{login_title}}
|
|
36
|
+
And User see [Email] field
|
|
37
|
+
And User see [Password] field
|
|
38
|
+
And User see [Remember me] checkbox is unchecked
|
|
39
|
+
And User see [Submit] button is enabled
|
|
40
|
+
And User see [Forgot password] link
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Action-Result Coherence Rules
|
|
44
|
+
|
|
45
|
+
Every scenario with a `When` action **must** assert the *result* of that action in `Then` — not just re-assert something already visible.
|
|
46
|
+
|
|
47
|
+
**Anti-patterns (WRONG):**
|
|
48
|
+
```gherkin
|
|
49
|
+
# BAD: click then assert the same element unchanged
|
|
50
|
+
When User click [Select language] button
|
|
51
|
+
Then User see [Select language] button
|
|
52
|
+
|
|
53
|
+
# BAD: fill then assert unrelated page (fill doesn't navigate)
|
|
54
|
+
When User fill [Search] field with {{term}}
|
|
55
|
+
Then User see [Home] page
|
|
56
|
+
|
|
57
|
+
# BAD: action with no meaningful result check
|
|
58
|
+
When User click [Submit] button
|
|
59
|
+
Then User see [Submit] button
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Correct patterns:**
|
|
63
|
+
```gherkin
|
|
64
|
+
# GOOD: click opens something new (dropdown, dialog, page)
|
|
65
|
+
When User click [Select language] button
|
|
66
|
+
Then User see [VN] button
|
|
67
|
+
|
|
68
|
+
# GOOD: click changes state on the element itself
|
|
69
|
+
When User click [Submit] button
|
|
70
|
+
Then User see [Submit] button is disabled
|
|
71
|
+
|
|
72
|
+
# GOOD: click navigates to different page
|
|
73
|
+
When User click [Login] button
|
|
74
|
+
Then User see [Dashboard] page
|
|
75
|
+
|
|
76
|
+
# GOOD: fill triggers visible result (search results, validation)
|
|
77
|
+
When User fill [Search] field with {{term}}
|
|
78
|
+
Then User see [search result] text with {{result_name}}
|
|
79
|
+
|
|
80
|
+
# GOOD: fill then submit, assert result of submission
|
|
81
|
+
When User fill [Email] field with {{invalid_email}}
|
|
82
|
+
And User click [Submit] button
|
|
83
|
+
Then User see [email error] message with {{email_error_text}}
|
|
84
|
+
|
|
85
|
+
# GOOD: click opens dialog
|
|
86
|
+
When User click [Submit] button
|
|
87
|
+
Then User see [Confirm] dialog
|
|
88
|
+
|
|
89
|
+
# GOOD: visibility-only scenario has no When (just Given + Then)
|
|
90
|
+
Given User is on [Login] page
|
|
91
|
+
Then User see [Email] field
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Rules:**
|
|
95
|
+
1. `When click [X]` → `Then` must assert either a **new element appears** (dialog, dropdown, page change, new content) or a **state change on `[X]` itself** (e.g., `is disabled`, `is checked`). Never assert `[X]` unchanged. Asserting something already visible before the click is a pre-existing state error — if the result is uncertain, mark `@manual`.
|
|
96
|
+
2. `When fill [X] field` → `Then` must assert the **visible result of the input** (search results appear, validation message shows, dropdown filters). Do NOT just assert the field has the value — `see [X] field with {{v}}` after fill is a **weak test** (Playwright fill already guarantees the value is set). Only use field value assertion when the field transforms the input (e.g., auto-format phone number, currency mask).
|
|
97
|
+
- **Search fields need a wait step** — search inputs typically have debounce/delay before results appear. After filling a search field, add `User wait for {{search_delay}}` before asserting results. Without this, the assertion fires before results render and the test flakes.
|
|
98
|
+
```gherkin
|
|
99
|
+
# GOOD: wait for debounce before asserting search results
|
|
100
|
+
When User fill [Search] field with {{term}}
|
|
101
|
+
And User wait for {{search_delay}}
|
|
102
|
+
Then User see [search result] text with {{result_name}}
|
|
103
|
+
```
|
|
104
|
+
3. If you only want to verify an element **exists/is visible** — use a UI/UX scenario with **no `When`** (just `Given` + `Then`)
|
|
105
|
+
4. If the result of an action is **unknown or uncertain** (e.g., what appears after filling a search, what dialog opens after click), either **explore via MCP first** to see the actual result, or **mark the scenario `@manual`**. Never guess the result — wrong assertions cause test failures that waste fix cycles.
|
|
106
|
+
5. Scenario **name must match the actual assertion**, not the action. "Fill searchbox shows search results" must assert search results — not field value.
|
|
107
|
+
|
|
108
|
+
## Quality Review Checklist (9 checks, auto-fix on detection)
|
|
109
|
+
|
|
110
|
+
After generating scenarios, review every scenario against these checks. **If an issue is detected, fix it immediately** — do not just flag it.
|
|
111
|
+
|
|
112
|
+
### 1. Redundant scenarios
|
|
113
|
+
|
|
114
|
+
**Problem:** Two scenarios test the same element with overlapping assertions.
|
|
115
|
+
```gherkin
|
|
116
|
+
# REDUNDANT: VP-UI-009 and VP-UI-010 both test CTA button
|
|
117
|
+
Scenario: CTA button is visible → Then see [cta] button
|
|
118
|
+
Scenario: CTA button shows text → Then see [cta] button with {{text}}
|
|
119
|
+
```
|
|
120
|
+
**Fix:** Keep only the stronger assertion (`with {{text}}` implies visibility). Remove the weaker one.
|
|
121
|
+
|
|
122
|
+
### 2. Misclassified viewpoint
|
|
123
|
+
|
|
124
|
+
**Problem:** A scenario classified in the wrong viewpoint category.
|
|
125
|
+
|
|
126
|
+
**Classification rules:**
|
|
127
|
+
- **UI/UX** = Given + Then asserting **static, always-the-same** defaults (layout, placeholder text, initial state on first-ever load)
|
|
128
|
+
- **Logic** = Given + When + Then (action causes a result), OR Given + Then asserting **behavior-dependent state** (persisted values, dynamic content, conditional defaults)
|
|
129
|
+
|
|
130
|
+
**Key distinction:** If the element's state depends on **previous user interaction, saved preferences, or business rules** — it's Logic even without a `When`, because it verifies behavior, not layout.
|
|
131
|
+
|
|
132
|
+
```gherkin
|
|
133
|
+
# UI/UX — static default, always the same for every user
|
|
134
|
+
Given User is on [Settings] page
|
|
135
|
+
Then User see [Language] dropdown with {{default_language}}
|
|
136
|
+
|
|
137
|
+
# Logic — checkbox remembers last user choice (persisted state)
|
|
138
|
+
Given User is on [Settings] page
|
|
139
|
+
Then User see [Newsletter] checkbox is checked
|
|
140
|
+
|
|
141
|
+
# Logic — empty state text depends on business rule (no data yet)
|
|
142
|
+
Given User is on [Orders] page
|
|
143
|
+
Then User see [empty state] text with {{no_orders_message}}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Fix:** Check whether the asserted state is truly static (same for all users, all times) or depends on data/behavior. Move accordingly.
|
|
147
|
+
|
|
148
|
+
### 3. Dynamic/data-dependent content
|
|
149
|
+
|
|
150
|
+
**Problem:** Asserting content that depends on live data which may change.
|
|
151
|
+
```gherkin
|
|
152
|
+
# FRAGILE: "Attachment 1" only exists if first card has an attachment
|
|
153
|
+
Scenario: Card shows attachment image
|
|
154
|
+
Then User see [Attachment 1] image
|
|
155
|
+
```
|
|
156
|
+
**Fix:** Mark as `@manual` with a comment explaining the data dependency.
|
|
157
|
+
|
|
158
|
+
### 4. Duplicate across sections
|
|
159
|
+
|
|
160
|
+
**Problem:** Security scenario has identical steps to a UI scenario.
|
|
161
|
+
```gherkin
|
|
162
|
+
# VP-UI-006 and VP-SEC-002 are identical
|
|
163
|
+
Scenario: VP-UI-006 User profile button is visible
|
|
164
|
+
Scenario: VP-SEC-002 Authenticated user sees profile button
|
|
165
|
+
```
|
|
166
|
+
**Fix:** Remove the duplicate. Security scenarios should test **auth boundaries** (e.g., `@no-auth` → redirect), not re-test visibility.
|
|
167
|
+
|
|
168
|
+
### 5. "Enabled" state on always-enabled elements
|
|
169
|
+
|
|
170
|
+
**Problem:** Testing `is enabled` on elements that have no disabled state in the application.
|
|
171
|
+
```gherkin
|
|
172
|
+
# BAD: this button is never disabled — the assertion adds no value
|
|
173
|
+
Then User see [Home] button is enabled
|
|
174
|
+
```
|
|
175
|
+
**Fix:** Remove. Only assert `is enabled` or `is disabled` when the element **actually toggles** between states based on conditions (e.g., form validity, permissions).
|
|
176
|
+
|
|
177
|
+
### 6. Exact match on dynamic counters/numbers
|
|
178
|
+
|
|
179
|
+
**Problem:** Using exact match (`with {{value}}`) on data that changes (counters, totals, timestamps).
|
|
180
|
+
```gherkin
|
|
181
|
+
# FRAGILE: "+61 KUDOS" changes when new kudos are sent
|
|
182
|
+
Then User see [kudos count] text with {{kudos_count}}
|
|
183
|
+
```
|
|
184
|
+
**Fix:** Use partial match (`text contains`) with a stable keyword:
|
|
185
|
+
```gherkin
|
|
186
|
+
Then User see [kudos count] text contains {{kudos_count_keyword}}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 7. Current active page link
|
|
190
|
+
|
|
191
|
+
**Problem:** Testing visibility of a nav link pointing to the current page.
|
|
192
|
+
```gherkin
|
|
193
|
+
# LOW VALUE: we are ON /kudos, Sun* Kudos link is always there
|
|
194
|
+
Scenario: Nav link Sun Kudos is visible
|
|
195
|
+
Given User is on [kudos] page
|
|
196
|
+
Then User see [Sun* Kudos] link
|
|
197
|
+
```
|
|
198
|
+
**Fix:** Remove or replace with active state test.
|
|
199
|
+
|
|
200
|
+
### 8. Test-data completeness
|
|
201
|
+
|
|
202
|
+
**Problem:** Feature file references `{{variable}}` but the corresponding key is missing in `test-data.yaml`.
|
|
203
|
+
```gherkin
|
|
204
|
+
# Feature uses {{login_error}} but test-data.yaml has no "login_error" key
|
|
205
|
+
When User fill [Email] field with {{invalid_email}}
|
|
206
|
+
And User click [Submit] button
|
|
207
|
+
Then User see [error] message with {{login_error}}
|
|
208
|
+
```
|
|
209
|
+
**Fix:** After generation, verify every `{{variable}}` in the `.feature` file has a matching entry in `test-data.yaml`. Add missing entries with realistic values. This is a **mandatory post-generation check** — missing test data causes compile failures.
|
|
210
|
+
|
|
211
|
+
### 9. Negative/boundary coverage
|
|
212
|
+
|
|
213
|
+
**Problem:** All scenarios are happy-path. No validation, error, or boundary cases exist.
|
|
214
|
+
```gherkin
|
|
215
|
+
# BAD: only tests successful login — what about invalid credentials?
|
|
216
|
+
Scenario: VP-LOGIC-001 User logs in successfully
|
|
217
|
+
Given User is on [Login] page
|
|
218
|
+
When User fill [Email] field with {{valid_email}}
|
|
219
|
+
And User fill [Password] field with {{valid_password}}
|
|
220
|
+
And User click [Submit] button
|
|
221
|
+
Then User see [Dashboard] page
|
|
222
|
+
```
|
|
223
|
+
**Fix:** For every form/input section, ensure at least one scenario covers:
|
|
224
|
+
- **Required field empty** → validation message appears
|
|
225
|
+
- **Invalid format** (email, phone, etc.) → format error appears
|
|
226
|
+
- **Boundary values** (max length, min value) → when relevant
|
|
227
|
+
|
|
228
|
+
If specific error messages are unknown, mark validation scenarios `@manual` rather than omitting them entirely.
|
|
@@ -7,12 +7,13 @@ user-invocable: false
|
|
|
7
7
|
## Standard Syntax
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
[Keyword] User <Action> [Target Name] <Target Type> <with {{Value}}> <is State>
|
|
10
|
+
[Keyword] User <Action> [Target Name] <Target Type> <in [Parent Name] <Parent Type>> <with {{Value}}> <is State>
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
- **Actor**: Always `User`, always active voice.
|
|
14
14
|
- **Value**: `with {{snake_case}}` — never hardcode static data.
|
|
15
15
|
- **State**: `is <keyword>` — never use `{{}}` for states.
|
|
16
|
+
- **Parent scope**: `in [Parent] parentType` — optional, only when page has 2+ similar blocks needing disambiguation.
|
|
16
17
|
|
|
17
18
|
## Keyword → Action Rules
|
|
18
19
|
|
|
@@ -88,8 +89,8 @@ User see [message text] alert # assert dialog message
|
|
|
88
89
|
### Keyboard
|
|
89
90
|
|
|
90
91
|
```
|
|
91
|
-
User press
|
|
92
|
-
User press
|
|
92
|
+
User press Escape key # global key press
|
|
93
|
+
User press Enter on [T] field # key on element
|
|
93
94
|
```
|
|
94
95
|
|
|
95
96
|
### Wait
|
|
@@ -112,11 +113,11 @@ User switch to [T] frame # enter iframe
|
|
|
112
113
|
User switch to [main] frame # exit iframe
|
|
113
114
|
```
|
|
114
115
|
|
|
115
|
-
### Assertions (
|
|
116
|
+
### Assertions (8 verify patterns)
|
|
116
117
|
|
|
117
118
|
```
|
|
118
119
|
# 1. Visibility
|
|
119
|
-
User see [T] message # visible (default)
|
|
120
|
+
User see [T] message # visible (default — NEVER add "is visible")
|
|
120
121
|
User see [T] modal is hidden # hidden
|
|
121
122
|
|
|
122
123
|
# 2. Text Content (exact full match — toHaveText)
|
|
@@ -140,26 +141,44 @@ User see [T] checkbox is checked # checked state
|
|
|
140
141
|
User see [T] toggle is unchecked # unchecked state
|
|
141
142
|
User see [T] dialog with {{v}} is hidden # text + state combined
|
|
142
143
|
|
|
143
|
-
# 6.
|
|
144
|
+
# 6. Attribute (toHaveAttribute — when selector YAML has `attribute` field)
|
|
145
|
+
User see [T] image with {{v}} # image src
|
|
146
|
+
User see [T] link with {{v}} # link href
|
|
147
|
+
|
|
148
|
+
# 7. Count
|
|
144
149
|
User see [T] row with {{count}} # element count
|
|
145
150
|
|
|
146
|
-
#
|
|
151
|
+
# 8. Page Context
|
|
147
152
|
User see [T] page # URL assertion
|
|
148
153
|
```
|
|
149
154
|
|
|
150
155
|
### Table
|
|
151
156
|
|
|
152
157
|
```
|
|
153
|
-
User see [
|
|
158
|
+
User see [Col] column in [Table] table # column exists (parent scoping)
|
|
159
|
+
User see [Table] table row with {{f}} # row exists
|
|
154
160
|
User see [Table] table has no row with {{f}} # row not exists
|
|
155
|
-
User see [Table] table
|
|
156
|
-
User see [Table] table has [Col] column # column exists
|
|
161
|
+
User see [Table] table with {{count}} rows # row count
|
|
157
162
|
User see [Table] table is empty # empty table
|
|
158
163
|
User see [Table] table row with {{f}} has [Col] with {{v}} # cell by filter
|
|
159
164
|
User see [Table] table row 1 [Col] cell with {{v}} # cell by index
|
|
160
165
|
User click [Act] in [Table] table row with {{f}} # action in row
|
|
161
166
|
```
|
|
162
167
|
|
|
168
|
+
### Parent Scoping (disambiguation)
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
User click [Submit] button in [User Info] form # button inside specific form
|
|
172
|
+
User fill [Email] field in [Registration] form with {{v}} # field inside specific form
|
|
173
|
+
User see [Total] text in [Summary] section with {{v}} # text inside specific section
|
|
174
|
+
User click [Delete] button in [Active Users] table # button inside specific table
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- **Optional** — only use when page has 2+ similar UI blocks
|
|
178
|
+
- **Valid parent types**: `table`, `list`, `section`, `dialog`, `form`
|
|
179
|
+
- **Max 2 levels**: `[Target] in [Parent]`. **NEVER** nest 3 levels: `[A] in [B] in [C]`
|
|
180
|
+
- Parent resolves from selectors YAML first, falls back to auto-infer `getByRole(parentType, { name })`
|
|
181
|
+
|
|
163
182
|
### States
|
|
164
183
|
|
|
165
184
|
`hidden` `visible` `disabled` `enabled` `checked` `unchecked` `focused` `empty` `loading` `selected` `sorted ascending` `sorted descending`
|
|
@@ -246,7 +265,7 @@ Options: `nth` `exact` `scope` `match` `variant` `frame` `contenteditable` `colu
|
|
|
246
265
|
|---|---|---|
|
|
247
266
|
| Wrong keyword | `Given User click [T] button` | `When User click [T] button` |
|
|
248
267
|
| Wrong action for type | `When User click [T] checkbox` | `When User check [T] checkbox` |
|
|
249
|
-
| press wrong target | `When User press [Submit] button` | `When User press
|
|
268
|
+
| press wrong target | `When User press [Submit] button` | `When User press Enter key` |
|
|
250
269
|
| uncheck radio | `When User uncheck [Male] radio` | `When User check [Female] radio` |
|
|
251
270
|
| Hardcode data | `with {{admin@mail.com}}` | `with {{invalid_email}}` |
|
|
252
271
|
| Missing `is` for state | `with {{text}} hidden` | `with {{text}} is hidden` |
|
|
@@ -124,6 +124,24 @@ To determine the correct `nth` offset, count how many matching elements appear b
|
|
|
124
124
|
|
|
125
125
|
---
|
|
126
126
|
|
|
127
|
+
### Step 4b: Handle Detail Screens with Dynamic IDs
|
|
128
|
+
|
|
129
|
+
For screens like `/admin/users/:id` or `/products/:slug`:
|
|
130
|
+
1. Navigate to the **list page** first via MCP browser to find a real record ID
|
|
131
|
+
2. Use that ID in the page selector value
|
|
132
|
+
3. Use `User is on [X] page` — sungen resolves the path from the selector
|
|
133
|
+
|
|
134
|
+
```yaml
|
|
135
|
+
# selectors.yaml — full path with real ID
|
|
136
|
+
user detail:
|
|
137
|
+
type: 'page'
|
|
138
|
+
value: '/admin/users/de42d800-0f5a-490e-9dcf-344fedbd34a5'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Note: the selector uses a hardcoded ID from the live page. If the record is deleted, update the ID in `selectors.yaml`.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
127
145
|
### Step 5: Handle SPA / Client-side Routing
|
|
128
146
|
|
|
129
147
|
Many modern apps (Next.js, Nuxt, SvelteKit, etc.) return the same HTML shell for all URLs and route client-side. `domcontentloaded` fires on the shell before the target page renders.
|
|
@@ -188,54 +206,102 @@ Many elements don't need a YAML entry — sungen auto-infers from the Gherkin la
|
|
|
188
206
|
|
|
189
207
|
---
|
|
190
208
|
|
|
191
|
-
###
|
|
209
|
+
### Proactive Selector Validation (before running tests)
|
|
192
210
|
|
|
193
|
-
|
|
211
|
+
**Most failures are selector mismatches.** Validate selectors against the live page BEFORE running any test — this eliminates slow compile→run→read→fix cycles.
|
|
194
212
|
|
|
213
|
+
After generating `selectors.yaml` (Step 3), verify each entry:
|
|
214
|
+
|
|
215
|
+
#### How to validate
|
|
216
|
+
|
|
217
|
+
Use `browser_evaluate` to check if each selector actually finds an element on the page:
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
// Validate a role selector
|
|
221
|
+
document.querySelectorAll('[role="button"]').length;
|
|
222
|
+
// or check accessible name exists
|
|
223
|
+
Array.from(document.querySelectorAll('button'))
|
|
224
|
+
.filter(el => el.textContent.includes('Submit') || el.getAttribute('aria-label')?.includes('Submit'))
|
|
225
|
+
.length;
|
|
195
226
|
```
|
|
196
|
-
1. INITIAL RUN — run ALL tests, collect full failure list
|
|
197
|
-
npx playwright test <spec> --reporter=line
|
|
198
227
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
228
|
+
Or use `browser_snapshot` and cross-check:
|
|
229
|
+
1. Read all `[Reference]` entries from `selectors.yaml`
|
|
230
|
+
2. Take a `browser_snapshot`
|
|
231
|
+
3. For each entry, verify:
|
|
232
|
+
- **role + name**: does the snapshot contain `button "Submit"` or `link "Home"`?
|
|
233
|
+
- **testid**: does `browser_evaluate` find `[data-testid="xxx"]`?
|
|
234
|
+
- **placeholder**: does the snapshot contain a textbox with that placeholder?
|
|
235
|
+
- **locator**: does `browser_evaluate` find `document.querySelector('xxx')`?
|
|
236
|
+
4. Fix mismatches immediately — no need to run tests
|
|
237
|
+
|
|
238
|
+
#### What to check
|
|
239
|
+
|
|
240
|
+
| Selector type | Validation method |
|
|
241
|
+
|---|---|
|
|
242
|
+
| `role` + `name` | Search snapshot for `role "name"` text |
|
|
243
|
+
| `testid` | `browser_evaluate`: `document.querySelector('[data-testid="xxx"]')` |
|
|
244
|
+
| `placeholder` | Search snapshot for textbox with placeholder |
|
|
245
|
+
| `locator` (CSS) | `browser_evaluate`: `document.querySelector('xxx')` |
|
|
246
|
+
| `page` | Verify URL path exists (navigate and check) |
|
|
247
|
+
|
|
248
|
+
#### Common proactive fixes
|
|
249
|
+
|
|
250
|
+
- Name mismatch → copy exact name from snapshot
|
|
251
|
+
- Element not found → check if element is inside iframe/dialog (needs `frame` or scope)
|
|
252
|
+
- Multiple matches → add `nth: 0` or `exact: true`
|
|
253
|
+
- No accessible name → switch to `testid` or `locator`
|
|
254
|
+
|
|
255
|
+
**Target: fix 80%+ of selector issues before the first test run.**
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
### Batched Test Execution
|
|
260
|
+
|
|
261
|
+
After proactive validation, run tests in **batches of 20** for faster feedback:
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
1. COMPILE — sungen generate --screen <screen>
|
|
265
|
+
|
|
266
|
+
2. BATCH RUN — run 20 tests at a time:
|
|
267
|
+
npx playwright test <spec> --grep "VP-UI-001|VP-UI-002|...|VP-UI-020" --reporter=line
|
|
268
|
+
|
|
269
|
+
3. IF FAILURES in batch:
|
|
270
|
+
a. Group failures by root cause (same selector, same error type)
|
|
271
|
+
b. Fix selectors.yaml or test-data.yaml
|
|
204
272
|
c. Recompile: sungen generate --screen <screen>
|
|
205
|
-
d. Re-run ONLY
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
273
|
+
d. Re-run ONLY the failing tests from this batch
|
|
274
|
+
e. If fixed → move to next batch
|
|
275
|
+
|
|
276
|
+
4. NEXT BATCH — repeat with next 20 tests (VP-UI-021...VP-UI-040)
|
|
209
277
|
|
|
210
|
-
|
|
278
|
+
5. FINAL CONFIRMATION — after all batches pass, run ALL tests once:
|
|
211
279
|
npx playwright test <spec> --reporter=line
|
|
212
280
|
This catches regressions from selector changes.
|
|
213
281
|
|
|
214
|
-
|
|
282
|
+
6. If still failing after 5 fix attempts per batch → ask user about direct .spec.ts fix
|
|
215
283
|
```
|
|
216
284
|
|
|
217
|
-
#### Building
|
|
285
|
+
#### Building batch `--grep` patterns
|
|
218
286
|
|
|
219
|
-
Extract scenario names
|
|
287
|
+
Extract scenario names and batch them:
|
|
220
288
|
```bash
|
|
221
|
-
#
|
|
222
|
-
npx playwright test <spec> --grep "VP-
|
|
223
|
-
```
|
|
289
|
+
# Batch 1: first 20
|
|
290
|
+
npx playwright test <spec> --grep "VP-UI-001|VP-UI-002|...|VP-UI-020" --reporter=line
|
|
224
291
|
|
|
225
|
-
|
|
226
|
-
|
|
292
|
+
# Batch 2: next 20
|
|
293
|
+
npx playwright test <spec> --grep "VP-VAL-001|VP-VAL-002|...|VP-VAL-020" --reporter=line
|
|
294
|
+
```
|
|
227
295
|
|
|
228
296
|
#### Grouping failures by root cause
|
|
229
297
|
|
|
230
298
|
Common patterns where 1 fix resolves many failures:
|
|
231
299
|
- **Same selector** — e.g., all `[Email Error]` tests fail → fix `email error` in selectors.yaml once
|
|
232
300
|
- **Same error type** — e.g., all `strict mode violation` → add `exact: true` or `nth`
|
|
233
|
-
- **Same assertion** — e.g., all `toHaveText` on inputs fail → change Gherkin pattern
|
|
301
|
+
- **Same assertion** — e.g., all `toHaveText` on inputs fail → change Gherkin pattern
|
|
234
302
|
|
|
235
303
|
Fix the root cause first, verify with the batch, then move on.
|
|
236
304
|
|
|
237
|
-
**Always read the error context snapshot first** — it shows the exact page state when the test failed, which is more reliable than re-navigating with MCP.
|
|
238
|
-
|
|
239
305
|
---
|
|
240
306
|
|
|
241
307
|
### Key Rules (from sungen-selector-keys)
|