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: README.md
+34-3Lines changed: 34 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -271,6 +271,31 @@ You can also take a snapshot on demand using `playwright-cli snapshot` command.
271
271
272
272
If `--filename` is not provided, a new snapshot file is created with a timestamp. Default to automatic file naming, use `--filename=` when artifact is a part of the workflow result.
273
273
274
+
### Targeting elements
275
+
276
+
By default, use refs from the snapshot to interact with page elements.
277
+
278
+
```bash
279
+
# get snapshot with refs
280
+
playwright-cli snapshot
281
+
282
+
# interact using a ref
283
+
playwright-cli click e15
284
+
```
285
+
286
+
You can also use css or role selectors, for example when explicitly asked for it.
In some cases you might want to install playwright-cli locally. If running the globally available `playwright-cli` binary fails, use `npx playwright-cli` to run the commands. For example:
312
+
If global `playwright-cli`command is not available, try a local version via `npx playwright-cli`:
313
+
314
+
```bash
315
+
npx --no-install playwright-cli --version
316
+
```
317
+
318
+
When local version is available, use `npx playwright-cli`in all commands. Otherwise, install `playwright-cli` as a global command:
288
319
289
320
```bash
290
-
npx playwright-cli open https://example.com
291
-
npx playwright-cli click e1
321
+
npm install -g @playwright/cli@latest
292
322
```
293
323
294
324
## Configuration file
@@ -488,6 +518,7 @@ Playwright CLI will load config from `.playwright/cli.config.json` by default so
488
518
489
519
The installed skill includes detailed reference guides for common tasks:
490
520
521
+
***Running and Debugging Playwright tests** — run, debug and manage Playwright test suites
491
522
***Request mocking** — intercept and mock network requests
Copy file name to clipboardExpand all lines: skills/playwright-cli/SKILL.md
+37-6Lines changed: 37 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
name: playwright-cli
3
-
description: Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.
4
-
allowed-tools: Bash(playwright-cli:*)
3
+
description: Automate browser interactions, test web pages and work with Playwright tests.
@@ -196,6 +196,31 @@ You can also take a snapshot on demand using `playwright-cli snapshot` command.
196
196
197
197
If `--filename` is not provided, a new snapshot file is created with a timestamp. Default to automatic file naming, use `--filename=` when artifact is a part of the workflow result.
198
198
199
+
## Targeting elements
200
+
201
+
By default, use refs from the snapshot to interact with page elements.
202
+
203
+
```bash
204
+
# get snapshot with refs
205
+
playwright-cli snapshot
206
+
207
+
# interact using a ref
208
+
playwright-cli click e15
209
+
```
210
+
211
+
You can also use css or role selectors, for example when explicitly asked for it.
If global `playwright-cli`command is not available, try a local version via `npx playwright-cli`:
245
+
246
+
```bash
247
+
npx --no-install playwright-cli --version
248
+
```
218
249
219
-
In some cases user might want to install playwright-cli locally. If running globally available `playwright-cli` binary fails, use `npx playwright-cli`to run the commands. For example:
250
+
When local version is available, use `npx playwright-cli`in all commands. Otherwise, install `playwright-cli`as a global command:
220
251
221
252
```bash
222
-
npx playwright-cli open https://example.com
223
-
npx playwright-cli click e1
253
+
npm install -g @playwright/cli@latest
224
254
```
225
255
226
256
## Example: Form submission
@@ -269,6 +299,7 @@ playwright-cli close
269
299
270
300
## Specific tasks
271
301
302
+
***Running and Debugging Playwright tests** [references/playwright-tests.md](references/playwright-tests.md)
To run Playwright tests, use the `npx playwright test` command, or a package manager script. To avoid opening the interactive html report, use `PLAYWRIGHT_HTML_OPEN=never` environment variable.
4
+
5
+
```bash
6
+
# Run all tests
7
+
PLAYWRIGHT_HTML_OPEN=never npx playwright test
8
+
9
+
# Run all tests through a custom npm script
10
+
PLAYWRIGHT_HTML_OPEN=never npm run special-test-command
11
+
```
12
+
13
+
# Debugging Playwright Tests
14
+
15
+
To debug a failing test, run it with Playwright as usual, but set `PWPAUSE=cli` environment variable. This command will pause the test at the point of failure, and print the debugging instructions.
16
+
17
+
**IMPORTANT**: run the command in the background and check the output until "Debugging Instructions" is printed.
18
+
19
+
Once instructions are printed, use `playwright-cli` to explore the page. Debugging instructions include a browser name that should be used in `playwright-cli` to attach to the page under test.
20
+
21
+
```bash
22
+
# Run the test
23
+
PLAYWRIGHT_HTML_OPEN=never PWPAUSE=cli npx playwright test
24
+
# ...
25
+
26
+
# Explore the page and interact if needed
27
+
playwright-cli --session=test open --attach=test-worker-abcdef
28
+
playwright-cli --session=test snapshot
29
+
playwright-cli --session=test click e14
30
+
```
31
+
32
+
Keep the test running in the background while you explore and look for a fix. After fixing the test, stop the background test run.
33
+
34
+
Every action you perform with `playwright-cli` generates corresponding Playwright TypeScript code.
35
+
This code appears in the output and can be copied directly into the test. Most of the time, a specific locator or an expectation should be updated, but it could also be a bug in the app. Use your judgement.
0 commit comments