vasu-playwright-utils 1.24.2 → 1.25.0
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 +23 -7
- package/package.json +9 -15
- package/scripts/setup.js +155 -0
- package/{cursor-rules → templates/cursor-rules}/playwright-agents.mdc +4 -4
- package/{cursor-rules → templates/cursor-rules}/vasu-playwright-utils.mdc +4 -4
- package/templates/skills/playwright-cli/SKILL.md +279 -0
- package/templates/skills/playwright-cli/references/request-mocking.md +87 -0
- package/templates/skills/playwright-cli/references/running-code.md +232 -0
- package/templates/skills/playwright-cli/references/session-management.md +170 -0
- package/templates/skills/playwright-cli/references/storage-state.md +275 -0
- package/templates/skills/playwright-cli/references/test-generation.md +88 -0
- package/templates/skills/playwright-cli/references/tracing.md +142 -0
- package/templates/skills/playwright-cli/references/video-recording.md +43 -0
- package/bin/setup.js +0 -173
- /package/{agents → templates/agents}/playwright-test-generator.md +0 -0
- /package/{agents → templates/agents}/playwright-test-healer.md +0 -0
- /package/{agents → templates/agents}/playwright-test-planner.md +0 -0
- /package/{cursor-rules → templates/cursor-rules}/project.mdc +0 -0
- /package/{skills → templates/skills}/vasu-playwright-utils/SKILL.md +0 -0
- /package/{skills → templates/skills}/vasu-playwright-utils/references/actions.md +0 -0
- /package/{skills → templates/skills}/vasu-playwright-utils/references/assertions.md +0 -0
- /package/{skills → templates/skills}/vasu-playwright-utils/references/browser-strategy.md +0 -0
- /package/{skills → templates/skills}/vasu-playwright-utils/references/locators.md +0 -0
package/README.md
CHANGED
|
@@ -123,6 +123,12 @@ To update after upgrading the library, run the command again with `--force`:
|
|
|
123
123
|
npx vasu-pw-setup --force
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
+
`--force` overwrites skills, agents, and cursor rules. To also overwrite `CLAUDE.md` (which is normally preserved), add `--force-claude`:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npx vasu-pw-setup --force --force-claude
|
|
130
|
+
```
|
|
131
|
+
|
|
126
132
|
### How skills and agents are invoked
|
|
127
133
|
|
|
128
134
|
- **Claude Code** auto-discovers `.claude/skills/` and `.claude/agents/`. `CLAUDE.md` instructs the agent to use `playwright-cli` and `vasu-playwright-utils` skills when writing tests, and to follow agent workflows (Planner / Generator / Healer) when asked to plan, generate, or fix tests.
|
|
@@ -132,17 +138,27 @@ To test: ask the agent to "write a test case to login for https://example.com" (
|
|
|
132
138
|
|
|
133
139
|
### For contributors
|
|
134
140
|
|
|
135
|
-
|
|
141
|
+
All distributable assets live under `templates/`. Symlinks make them available to Claude Code and Cursor during local development — edit the source in `templates/` and changes are reflected everywhere:
|
|
136
142
|
|
|
137
|
-
| Symlink | Source of truth
|
|
138
|
-
| ----------------------------------------- |
|
|
139
|
-
| `.claude/skills/vasu-playwright-utils` | `skills/vasu-playwright-utils/` |
|
|
140
|
-
| `.claude/
|
|
141
|
-
| `.
|
|
142
|
-
| `.cursor/rules/
|
|
143
|
+
| Symlink | Source of truth |
|
|
144
|
+
| ----------------------------------------- | -------------------------------------------------- |
|
|
145
|
+
| `.claude/skills/vasu-playwright-utils` | `templates/skills/vasu-playwright-utils/` |
|
|
146
|
+
| `.claude/skills/playwright-cli` | `templates/skills/playwright-cli/` |
|
|
147
|
+
| `.claude/agents` | `templates/agents/` |
|
|
148
|
+
| `.cursor/rules/playwright-agents.mdc` | `templates/cursor-rules/playwright-agents.mdc` |
|
|
149
|
+
| `.cursor/rules/vasu-playwright-utils.mdc` | `templates/cursor-rules/vasu-playwright-utils.mdc` |
|
|
150
|
+
| `.cursor/rules/project.mdc` | `templates/cursor-rules/project.mdc` |
|
|
143
151
|
|
|
144
152
|
`.cursor/rules/project.mdc` loads `CLAUDE.md` into Cursor so both Claude Code and Cursor share the same project instructions.
|
|
145
153
|
|
|
154
|
+
#### Syncing `playwright-cli` skill into `templates/`
|
|
155
|
+
|
|
156
|
+
After refreshing the skill locally (e.g. `npx skills update microsoft/playwright-cli --skill playwright-cli -a claude-code` so `.claude/skills/playwright-cli` is current), sync it into templates and commit:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm run sync:playwright-cli-skill
|
|
160
|
+
```
|
|
161
|
+
|
|
146
162
|
## Issues and Feedback
|
|
147
163
|
|
|
148
164
|
If you encounter any issues or have feedback, please [Raise an Issue](https://github.com/vasu31dev/playwright-ts-lib/issues) on GitHub.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vasu-playwright-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.0",
|
|
4
4
|
"description": "Playwright Typescript Library with reusable utilities",
|
|
5
5
|
"main": "./dist/src/vasu-playwright-lib/index.js",
|
|
6
6
|
"types": "./dist/src/vasu-playwright-lib/index.d.ts",
|
|
@@ -40,16 +40,13 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"bin": {
|
|
43
|
-
"vasu-pw-setup": "
|
|
43
|
+
"vasu-pw-setup": "scripts/setup.js"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist",
|
|
47
47
|
"src",
|
|
48
48
|
"eslint.config.base.mjs",
|
|
49
|
-
"
|
|
50
|
-
"agents",
|
|
51
|
-
"cursor-rules",
|
|
52
|
-
"bin",
|
|
49
|
+
"scripts",
|
|
53
50
|
"templates"
|
|
54
51
|
],
|
|
55
52
|
"engines": {
|
|
@@ -57,10 +54,9 @@
|
|
|
57
54
|
},
|
|
58
55
|
"dependencies": {
|
|
59
56
|
"@eslint/js": "^9.39.4",
|
|
60
|
-
"@playwright/cli": "^0.1.1",
|
|
61
57
|
"@types/node": "^25.5.0",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^8.57.
|
|
63
|
-
"@typescript-eslint/parser": "^8.57.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^8.57.2",
|
|
59
|
+
"@typescript-eslint/parser": "^8.57.2",
|
|
64
60
|
"cross-env": "^10.1.0",
|
|
65
61
|
"dotenv": "^17.3.1",
|
|
66
62
|
"eslint": "^9.39.4",
|
|
@@ -81,12 +77,9 @@
|
|
|
81
77
|
"peerDependencies": {
|
|
82
78
|
"@playwright/test": ">=1.58.2"
|
|
83
79
|
},
|
|
84
|
-
"overrides": {
|
|
85
|
-
"playwright": "^1.58.2"
|
|
86
|
-
},
|
|
87
80
|
"scripts": {
|
|
88
|
-
"ncu:check": "npx npm-check-updates --reject \"eslint,@eslint/js\" --dep prod,dev,optional,peer && npx npm-check-updates \"eslint,@eslint/js\" --target minor --deep peer",
|
|
89
|
-
"ncu:update": "npx npm-check-updates --reject \"eslint,@eslint/js\" --dep prod,dev,optional,peer -u && npx npm-check-updates \"eslint,@eslint/js\" --target minor --deep peer -u",
|
|
81
|
+
"ncu:check": "npx npm-check-updates --reject \"eslint,@eslint/js,typescript\" --dep prod,dev,optional,peer && npx npm-check-updates \"eslint,@eslint/js\" --target minor --deep peer && npx npm-check-updates typescript --target minor",
|
|
82
|
+
"ncu:update": "npx npm-check-updates --reject \"eslint,@eslint/js,typescript\" --dep prod,dev,optional,peer -u && npx npm-check-updates \"eslint,@eslint/js\" --target minor --deep peer -u && npx npm-check-updates typescript --target minor -u",
|
|
90
83
|
"clean": "rimraf dist",
|
|
91
84
|
"prebuild": "npm run clean",
|
|
92
85
|
"build": "tsc -p tsconfig.build.json",
|
|
@@ -110,7 +103,8 @@
|
|
|
110
103
|
"prepare": "husky",
|
|
111
104
|
"format": "cross-env prettier --write 'src/**/*.ts' 'tests/**/*.ts' 'test-setup/**/*.ts' 'playwright.config.ts' '**/*.json' '**/*.md' '!package-lock.json' '!dist/**/*' '!build/**/*'",
|
|
112
105
|
"postinstall": "playwright install chromium",
|
|
113
|
-
"setup": "node
|
|
106
|
+
"setup": "node scripts/setup.js",
|
|
107
|
+
"sync:playwright-cli-skill": "rm -rf templates/skills/playwright-cli && cp -r .claude/skills/playwright-cli templates/skills/playwright-cli"
|
|
114
108
|
},
|
|
115
109
|
"husky": {
|
|
116
110
|
"hooks": {
|
package/scripts/setup.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
const FORCE = args.includes('--force');
|
|
10
|
+
const FORCE_CLAUDE = args.includes('--force-claude');
|
|
11
|
+
const skillsFlag = args.includes('--skills');
|
|
12
|
+
const agentsFlag = args.includes('--agents');
|
|
13
|
+
// No flags → full install. One flag → that part only. Both flags → full install (same as neither).
|
|
14
|
+
const noScopeFlags = !skillsFlag && !agentsFlag;
|
|
15
|
+
const INSTALL_SKILLS = noScopeFlags || skillsFlag;
|
|
16
|
+
const INSTALL_AGENTS = noScopeFlags || agentsFlag;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Resolve the consumer project root.
|
|
20
|
+
* - INIT_CWD is set by npm/yarn when running lifecycle scripts or npx.
|
|
21
|
+
* - Falls back to walking up from cwd looking for package.json.
|
|
22
|
+
*/
|
|
23
|
+
function resolveProjectRoot() {
|
|
24
|
+
if (process.env.INIT_CWD) {
|
|
25
|
+
return process.env.INIT_CWD;
|
|
26
|
+
}
|
|
27
|
+
let dir = process.cwd();
|
|
28
|
+
while (dir !== path.dirname(dir)) {
|
|
29
|
+
if (fs.existsSync(path.join(dir, 'package.json'))) {
|
|
30
|
+
return dir;
|
|
31
|
+
}
|
|
32
|
+
dir = path.dirname(dir);
|
|
33
|
+
}
|
|
34
|
+
return process.cwd();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Recursively copy a directory, skipping existing files unless force is true.
|
|
39
|
+
*/
|
|
40
|
+
function copyDirSync(src, dest, force) {
|
|
41
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
42
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
43
|
+
const srcPath = path.join(src, entry.name);
|
|
44
|
+
const destPath = path.join(dest, entry.name);
|
|
45
|
+
if (entry.isDirectory()) {
|
|
46
|
+
copyDirSync(srcPath, destPath, force);
|
|
47
|
+
} else {
|
|
48
|
+
if (!force && fs.existsSync(destPath)) {
|
|
49
|
+
console.log(` [skip] ${path.relative(projectRoot, destPath)} (exists, use --force to overwrite)`);
|
|
50
|
+
} else {
|
|
51
|
+
fs.copyFileSync(srcPath, destPath);
|
|
52
|
+
console.log(` [copy] ${path.relative(projectRoot, destPath)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Install a directory component by copying from package templates to consumer project.
|
|
60
|
+
*/
|
|
61
|
+
function installDir(name, src, dest, force) {
|
|
62
|
+
if (!fs.existsSync(src)) {
|
|
63
|
+
console.error(`\nError: ${name} source not found at`, src);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
console.log(`\n${step++}. Installing ${name}:`);
|
|
67
|
+
copyDirSync(src, dest, force);
|
|
68
|
+
installed.push(path.relative(projectRoot, dest));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Install a single file, skipping if it exists and force is false.
|
|
73
|
+
*/
|
|
74
|
+
function installFile(src, dest, force) {
|
|
75
|
+
const rel = path.relative(projectRoot, dest);
|
|
76
|
+
if (!force && fs.existsSync(dest)) {
|
|
77
|
+
console.log(` [skip] ${rel} (exists, use --force to overwrite)`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!fs.existsSync(src)) {
|
|
81
|
+
console.log(` [skip] ${rel} (source not found)`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
85
|
+
fs.copyFileSync(src, dest);
|
|
86
|
+
console.log(` [copy] ${rel}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// --- Main ---
|
|
90
|
+
|
|
91
|
+
const projectRoot = resolveProjectRoot();
|
|
92
|
+
const pkgDir = path.resolve(__dirname, '..');
|
|
93
|
+
const templatesDir = path.join(pkgDir, 'templates');
|
|
94
|
+
const installed = [];
|
|
95
|
+
let step = 1;
|
|
96
|
+
|
|
97
|
+
console.log('vasu-playwright-utils: Setting up AI skills and agents...\n');
|
|
98
|
+
console.log(`Project root: ${projectRoot}`);
|
|
99
|
+
|
|
100
|
+
if (INSTALL_SKILLS) {
|
|
101
|
+
installDir(
|
|
102
|
+
'vasu-playwright-utils skills',
|
|
103
|
+
path.join(templatesDir, 'skills', 'vasu-playwright-utils'),
|
|
104
|
+
path.join(projectRoot, '.claude', 'skills', 'vasu-playwright-utils'),
|
|
105
|
+
FORCE,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
installDir(
|
|
109
|
+
'playwright-cli skills',
|
|
110
|
+
path.join(templatesDir, 'skills', 'playwright-cli'),
|
|
111
|
+
path.join(projectRoot, '.claude', 'skills', 'playwright-cli'),
|
|
112
|
+
FORCE,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
console.log(`\n${step++}. Installing Cursor rules (skills):`);
|
|
116
|
+
installFile(
|
|
117
|
+
path.join(templatesDir, 'cursor-rules', 'vasu-playwright-utils.mdc'),
|
|
118
|
+
path.join(projectRoot, '.cursor', 'rules', 'vasu-playwright-utils.mdc'),
|
|
119
|
+
FORCE,
|
|
120
|
+
);
|
|
121
|
+
installFile(
|
|
122
|
+
path.join(templatesDir, 'cursor-rules', 'project.mdc'),
|
|
123
|
+
path.join(projectRoot, '.cursor', 'rules', 'project.mdc'),
|
|
124
|
+
FORCE,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
console.log(`\n${step++}. Installing CLAUDE.md template:`);
|
|
128
|
+
installFile(path.join(templatesDir, 'CLAUDE.md'), path.join(projectRoot, 'CLAUDE.md'), FORCE_CLAUDE);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (INSTALL_AGENTS) {
|
|
132
|
+
installDir(
|
|
133
|
+
'playwright agents',
|
|
134
|
+
path.join(templatesDir, 'agents'),
|
|
135
|
+
path.join(projectRoot, '.claude', 'agents'),
|
|
136
|
+
FORCE,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
console.log(`\n${step++}. Installing Cursor rules (agents):`);
|
|
140
|
+
installFile(
|
|
141
|
+
path.join(templatesDir, 'cursor-rules', 'playwright-agents.mdc'),
|
|
142
|
+
path.join(projectRoot, '.cursor', 'rules', 'playwright-agents.mdc'),
|
|
143
|
+
FORCE,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Summary
|
|
148
|
+
console.log('\nDone! Installed to:');
|
|
149
|
+
for (const p of installed) {
|
|
150
|
+
console.log(` ${p}`);
|
|
151
|
+
}
|
|
152
|
+
console.log('\nBoth Claude Code and Cursor will auto-discover:');
|
|
153
|
+
console.log(' .claude/skills/ — API skills (Claude Code & Cursor via .cursor/rules/)');
|
|
154
|
+
console.log(' .claude/agents/ — Agent workflows (Claude Code)');
|
|
155
|
+
console.log(' .cursor/rules/ — Cursor rules referencing .claude/ skills and agents\n');
|
|
@@ -8,7 +8,7 @@ globs: ["**/*.spec.ts", "**/*.test.ts", "specs/**", "tests/**"]
|
|
|
8
8
|
When working on Playwright tests you **must**:
|
|
9
9
|
|
|
10
10
|
1. **Use `playwright-cli`** to verify flows — run `playwright-cli open <url>`, `playwright-cli snapshot`, then interact (click, fill) to capture real selectors. Never guess selectors.
|
|
11
|
-
2. **Follow the locator strategy** in
|
|
11
|
+
2. **Follow the locator strategy** in `.claude/skills/vasu-playwright-utils/references/locators.md` when writing selectors.
|
|
12
12
|
3. **Use the right agent workflow** when the user asks to:
|
|
13
13
|
- Create a test plan or explore an app → **Test Planner**
|
|
14
14
|
- Generate a test from a plan or scenario → **Test Generator**
|
|
@@ -25,6 +25,6 @@ When working on Playwright tests you **must**:
|
|
|
25
25
|
|
|
26
26
|
## Agent Details
|
|
27
27
|
|
|
28
|
-
@file agents/playwright-test-planner.md
|
|
29
|
-
@file agents/playwright-test-generator.md
|
|
30
|
-
@file agents/playwright-test-healer.md
|
|
28
|
+
@file .claude/agents/playwright-test-planner.md
|
|
29
|
+
@file .claude/agents/playwright-test-generator.md
|
|
30
|
+
@file .claude/agents/playwright-test-healer.md
|
|
@@ -20,7 +20,7 @@ Playwright TypeScript utility library with simplified helper functions for brows
|
|
|
20
20
|
|
|
21
21
|
## Full API Documentation
|
|
22
22
|
|
|
23
|
-
@file skills/vasu-playwright-utils/SKILL.md
|
|
24
|
-
@file skills/vasu-playwright-utils/references/actions.md
|
|
25
|
-
@file skills/vasu-playwright-utils/references/assertions.md
|
|
26
|
-
@file skills/vasu-playwright-utils/references/locators.md
|
|
23
|
+
@file .claude/skills/vasu-playwright-utils/SKILL.md
|
|
24
|
+
@file .claude/skills/vasu-playwright-utils/references/actions.md
|
|
25
|
+
@file .claude/skills/vasu-playwright-utils/references/assertions.md
|
|
26
|
+
@file .claude/skills/vasu-playwright-utils/references/locators.md
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
---
|
|
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:*)
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Browser Automation with playwright-cli
|
|
8
|
+
|
|
9
|
+
## Quick start
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# open new browser
|
|
13
|
+
playwright-cli open
|
|
14
|
+
# navigate to a page
|
|
15
|
+
playwright-cli goto https://playwright.dev
|
|
16
|
+
# interact with the page using refs from the snapshot
|
|
17
|
+
playwright-cli click e15
|
|
18
|
+
playwright-cli type "page.click"
|
|
19
|
+
playwright-cli press Enter
|
|
20
|
+
# take a screenshot (rarely used, as snapshot is more common)
|
|
21
|
+
playwright-cli screenshot
|
|
22
|
+
# close the browser
|
|
23
|
+
playwright-cli close
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Commands
|
|
27
|
+
|
|
28
|
+
### Core
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
playwright-cli open
|
|
32
|
+
# open and navigate right away
|
|
33
|
+
playwright-cli open https://example.com/
|
|
34
|
+
playwright-cli goto https://playwright.dev
|
|
35
|
+
playwright-cli type "search query"
|
|
36
|
+
playwright-cli click e3
|
|
37
|
+
playwright-cli dblclick e7
|
|
38
|
+
playwright-cli fill e5 "user@example.com"
|
|
39
|
+
playwright-cli drag e2 e8
|
|
40
|
+
playwright-cli hover e4
|
|
41
|
+
playwright-cli select e9 "option-value"
|
|
42
|
+
playwright-cli upload ./document.pdf
|
|
43
|
+
playwright-cli check e12
|
|
44
|
+
playwright-cli uncheck e12
|
|
45
|
+
playwright-cli snapshot
|
|
46
|
+
playwright-cli snapshot --filename=after-click.yaml
|
|
47
|
+
playwright-cli eval "document.title"
|
|
48
|
+
playwright-cli eval "el => el.textContent" e5
|
|
49
|
+
playwright-cli dialog-accept
|
|
50
|
+
playwright-cli dialog-accept "confirmation text"
|
|
51
|
+
playwright-cli dialog-dismiss
|
|
52
|
+
playwright-cli resize 1920 1080
|
|
53
|
+
playwright-cli close
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Navigation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
playwright-cli go-back
|
|
60
|
+
playwright-cli go-forward
|
|
61
|
+
playwright-cli reload
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Keyboard
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
playwright-cli press Enter
|
|
68
|
+
playwright-cli press ArrowDown
|
|
69
|
+
playwright-cli keydown Shift
|
|
70
|
+
playwright-cli keyup Shift
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Mouse
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
playwright-cli mousemove 150 300
|
|
77
|
+
playwright-cli mousedown
|
|
78
|
+
playwright-cli mousedown right
|
|
79
|
+
playwright-cli mouseup
|
|
80
|
+
playwright-cli mouseup right
|
|
81
|
+
playwright-cli mousewheel 0 100
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Save as
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
playwright-cli screenshot
|
|
88
|
+
playwright-cli screenshot e5
|
|
89
|
+
playwright-cli screenshot --filename=page.png
|
|
90
|
+
playwright-cli pdf --filename=page.pdf
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Tabs
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
playwright-cli tab-list
|
|
97
|
+
playwright-cli tab-new
|
|
98
|
+
playwright-cli tab-new https://example.com/page
|
|
99
|
+
playwright-cli tab-close
|
|
100
|
+
playwright-cli tab-close 2
|
|
101
|
+
playwright-cli tab-select 0
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Storage
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
playwright-cli state-save
|
|
108
|
+
playwright-cli state-save auth.json
|
|
109
|
+
playwright-cli state-load auth.json
|
|
110
|
+
|
|
111
|
+
# Cookies
|
|
112
|
+
playwright-cli cookie-list
|
|
113
|
+
playwright-cli cookie-list --domain=example.com
|
|
114
|
+
playwright-cli cookie-get session_id
|
|
115
|
+
playwright-cli cookie-set session_id abc123
|
|
116
|
+
playwright-cli cookie-set session_id abc123 --domain=example.com --httpOnly --secure
|
|
117
|
+
playwright-cli cookie-delete session_id
|
|
118
|
+
playwright-cli cookie-clear
|
|
119
|
+
|
|
120
|
+
# LocalStorage
|
|
121
|
+
playwright-cli localstorage-list
|
|
122
|
+
playwright-cli localstorage-get theme
|
|
123
|
+
playwright-cli localstorage-set theme dark
|
|
124
|
+
playwright-cli localstorage-delete theme
|
|
125
|
+
playwright-cli localstorage-clear
|
|
126
|
+
|
|
127
|
+
# SessionStorage
|
|
128
|
+
playwright-cli sessionstorage-list
|
|
129
|
+
playwright-cli sessionstorage-get step
|
|
130
|
+
playwright-cli sessionstorage-set step 3
|
|
131
|
+
playwright-cli sessionstorage-delete step
|
|
132
|
+
playwright-cli sessionstorage-clear
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Network
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
playwright-cli route "**/*.jpg" --status=404
|
|
139
|
+
playwright-cli route "https://api.example.com/**" --body='{"mock": true}'
|
|
140
|
+
playwright-cli route-list
|
|
141
|
+
playwright-cli unroute "**/*.jpg"
|
|
142
|
+
playwright-cli unroute
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### DevTools
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
playwright-cli console
|
|
149
|
+
playwright-cli console warning
|
|
150
|
+
playwright-cli network
|
|
151
|
+
playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])"
|
|
152
|
+
playwright-cli tracing-start
|
|
153
|
+
playwright-cli tracing-stop
|
|
154
|
+
playwright-cli video-start
|
|
155
|
+
playwright-cli video-stop video.webm
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Open parameters
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Use specific browser when creating session
|
|
162
|
+
playwright-cli open --browser=chrome
|
|
163
|
+
playwright-cli open --browser=firefox
|
|
164
|
+
playwright-cli open --browser=webkit
|
|
165
|
+
playwright-cli open --browser=msedge
|
|
166
|
+
# Connect to browser via extension
|
|
167
|
+
playwright-cli open --extension
|
|
168
|
+
|
|
169
|
+
# Use persistent profile (by default profile is in-memory)
|
|
170
|
+
playwright-cli open --persistent
|
|
171
|
+
# Use persistent profile with custom directory
|
|
172
|
+
playwright-cli open --profile=/path/to/profile
|
|
173
|
+
|
|
174
|
+
# Start with config file
|
|
175
|
+
playwright-cli open --config=my-config.json
|
|
176
|
+
|
|
177
|
+
# Close the browser
|
|
178
|
+
playwright-cli close
|
|
179
|
+
# Delete user data for the default session
|
|
180
|
+
playwright-cli delete-data
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Snapshots
|
|
184
|
+
|
|
185
|
+
After each command, playwright-cli provides a snapshot of the current browser state.
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
> playwright-cli goto https://example.com
|
|
189
|
+
### Page
|
|
190
|
+
- Page URL: https://example.com/
|
|
191
|
+
- Page Title: Example Domain
|
|
192
|
+
### Snapshot
|
|
193
|
+
[Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
You can also take a snapshot on demand using `playwright-cli snapshot` command.
|
|
197
|
+
|
|
198
|
+
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.
|
|
199
|
+
|
|
200
|
+
## Browser Sessions
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
# create new browser session named "mysession" with persistent profile
|
|
204
|
+
playwright-cli -s=mysession open example.com --persistent
|
|
205
|
+
# same with manually specified profile directory (use when requested explicitly)
|
|
206
|
+
playwright-cli -s=mysession open example.com --profile=/path/to/profile
|
|
207
|
+
playwright-cli -s=mysession click e6
|
|
208
|
+
playwright-cli -s=mysession close # stop a named browser
|
|
209
|
+
playwright-cli -s=mysession delete-data # delete user data for persistent session
|
|
210
|
+
|
|
211
|
+
playwright-cli list
|
|
212
|
+
# Close all browsers
|
|
213
|
+
playwright-cli close-all
|
|
214
|
+
# Forcefully kill all browser processes
|
|
215
|
+
playwright-cli kill-all
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Local installation
|
|
219
|
+
|
|
220
|
+
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:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
npx playwright-cli open https://example.com
|
|
224
|
+
npx playwright-cli click e1
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Example: Form submission
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
playwright-cli open https://example.com/form
|
|
231
|
+
playwright-cli snapshot
|
|
232
|
+
|
|
233
|
+
playwright-cli fill e1 "user@example.com"
|
|
234
|
+
playwright-cli fill e2 "password123"
|
|
235
|
+
playwright-cli click e3
|
|
236
|
+
playwright-cli snapshot
|
|
237
|
+
playwright-cli close
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Example: Multi-tab workflow
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
playwright-cli open https://example.com
|
|
244
|
+
playwright-cli tab-new https://example.com/other
|
|
245
|
+
playwright-cli tab-list
|
|
246
|
+
playwright-cli tab-select 0
|
|
247
|
+
playwright-cli snapshot
|
|
248
|
+
playwright-cli close
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Example: Debugging with DevTools
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
playwright-cli open https://example.com
|
|
255
|
+
playwright-cli click e4
|
|
256
|
+
playwright-cli fill e7 "test"
|
|
257
|
+
playwright-cli console
|
|
258
|
+
playwright-cli network
|
|
259
|
+
playwright-cli close
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
playwright-cli open https://example.com
|
|
264
|
+
playwright-cli tracing-start
|
|
265
|
+
playwright-cli click e4
|
|
266
|
+
playwright-cli fill e7 "test"
|
|
267
|
+
playwright-cli tracing-stop
|
|
268
|
+
playwright-cli close
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Specific tasks
|
|
272
|
+
|
|
273
|
+
- **Request mocking** [references/request-mocking.md](references/request-mocking.md)
|
|
274
|
+
- **Running Playwright code** [references/running-code.md](references/running-code.md)
|
|
275
|
+
- **Browser session management** [references/session-management.md](references/session-management.md)
|
|
276
|
+
- **Storage state (cookies, localStorage)** [references/storage-state.md](references/storage-state.md)
|
|
277
|
+
- **Test generation** [references/test-generation.md](references/test-generation.md)
|
|
278
|
+
- **Tracing** [references/tracing.md](references/tracing.md)
|
|
279
|
+
- **Video recording** [references/video-recording.md](references/video-recording.md)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Request Mocking
|
|
2
|
+
|
|
3
|
+
Intercept, mock, modify, and block network requests.
|
|
4
|
+
|
|
5
|
+
## CLI Route Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Mock with custom status
|
|
9
|
+
playwright-cli route "**/*.jpg" --status=404
|
|
10
|
+
|
|
11
|
+
# Mock with JSON body
|
|
12
|
+
playwright-cli route "**/api/users" --body='[{"id":1,"name":"Alice"}]' --content-type=application/json
|
|
13
|
+
|
|
14
|
+
# Mock with custom headers
|
|
15
|
+
playwright-cli route "**/api/data" --body='{"ok":true}' --header="X-Custom: value"
|
|
16
|
+
|
|
17
|
+
# Remove headers from requests
|
|
18
|
+
playwright-cli route "**/*" --remove-header=cookie,authorization
|
|
19
|
+
|
|
20
|
+
# List active routes
|
|
21
|
+
playwright-cli route-list
|
|
22
|
+
|
|
23
|
+
# Remove a route or all routes
|
|
24
|
+
playwright-cli unroute "**/*.jpg"
|
|
25
|
+
playwright-cli unroute
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## URL Patterns
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
**/api/users - Exact path match
|
|
32
|
+
**/api/*/details - Wildcard in path
|
|
33
|
+
**/*.{png,jpg,jpeg} - Match file extensions
|
|
34
|
+
**/search?q=* - Match query parameters
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Advanced Mocking with run-code
|
|
38
|
+
|
|
39
|
+
For conditional responses, request body inspection, response modification, or delays:
|
|
40
|
+
|
|
41
|
+
### Conditional Response Based on Request
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
playwright-cli run-code "async page => {
|
|
45
|
+
await page.route('**/api/login', route => {
|
|
46
|
+
const body = route.request().postDataJSON();
|
|
47
|
+
if (body.username === 'admin') {
|
|
48
|
+
route.fulfill({ body: JSON.stringify({ token: 'mock-token' }) });
|
|
49
|
+
} else {
|
|
50
|
+
route.fulfill({ status: 401, body: JSON.stringify({ error: 'Invalid' }) });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Modify Real Response
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
playwright-cli run-code "async page => {
|
|
60
|
+
await page.route('**/api/user', async route => {
|
|
61
|
+
const response = await route.fetch();
|
|
62
|
+
const json = await response.json();
|
|
63
|
+
json.isPremium = true;
|
|
64
|
+
await route.fulfill({ response, json });
|
|
65
|
+
});
|
|
66
|
+
}"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Simulate Network Failures
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
playwright-cli run-code "async page => {
|
|
73
|
+
await page.route('**/api/offline', route => route.abort('internetdisconnected'));
|
|
74
|
+
}"
|
|
75
|
+
# Options: connectionrefused, timedout, connectionreset, internetdisconnected
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Delayed Response
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
playwright-cli run-code "async page => {
|
|
82
|
+
await page.route('**/api/slow', async route => {
|
|
83
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
84
|
+
route.fulfill({ body: JSON.stringify({ data: 'loaded' }) });
|
|
85
|
+
});
|
|
86
|
+
}"
|
|
87
|
+
```
|