You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: skills/playwright-cli/references/test-generation.md
+49-3Lines changed: 49 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,12 +77,58 @@ playwright-cli click e5
77
77
78
78
### 3. Add Assertions Manually
79
79
80
-
Generated code captures actions but not assertions. Add expectations in your test:
80
+
Generated code captures actions but not assertions. Add expectations in your test using one of the recommended matchers:
81
+
82
+
-`toBeVisible()` — element is rendered and visible
83
+
-`toHaveText(text)` — element text content matches
84
+
-`toHaveValue(value) / toBeEmpty()` — input/select value matches
85
+
-`toBeChecked() / toBeUnchecked()` — checkbox state matches
86
+
-`toMatchAriaSnapshot(snapshot)` — page (or locator) matches a partial accessibility snapshot
87
+
88
+
Use `playwright-cli generate-locator <target>` to produce the locator expression for the assertion, and the snapshot/eval commands to capture the expected value.
89
+
90
+
When asserting text content, make sure that generated locator does not contain text from the element itself. `getByTestId()` or `getByLabel()` usually work well with asserting text. When locator is text-based, prefer `toBeVisible()` instead.
91
+
92
+
Snapshot to be matched does not have to contain all the information - only capture what's necessary for the assertion. You can use regular expressions for unstable values.
93
+
94
+
```bash
95
+
# Get a stable locator for an element ref to use in the assertion
0 commit comments