@kamleshsk/claude-qa 1.0.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/bin/install.js +56 -0
- package/package.json +22 -0
- package/templates/commands/qa-setup.md +2990 -0
- package/templates/commands/qa.md +231 -0
- package/templates/docs/qa-setup/module-guide.md +398 -0
- package/templates/skills/playwright-cli/SKILL.md +388 -0
- package/templates/skills/playwright-cli/references/element-attributes.md +23 -0
- package/templates/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/templates/skills/playwright-cli/references/request-mocking.md +87 -0
- package/templates/skills/playwright-cli/references/running-code.md +241 -0
- package/templates/skills/playwright-cli/references/session-management.md +225 -0
- package/templates/skills/playwright-cli/references/spec-driven-testing.md +305 -0
- package/templates/skills/playwright-cli/references/storage-state.md +275 -0
- package/templates/skills/playwright-cli/references/test-generation.md +134 -0
- package/templates/skills/playwright-cli/references/tracing.md +139 -0
- package/templates/skills/playwright-cli/references/video-recording.md +143 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# Running Custom Playwright Code
|
|
2
|
+
|
|
3
|
+
Use `run-code` to execute arbitrary Playwright code for advanced scenarios not covered by CLI commands.
|
|
4
|
+
|
|
5
|
+
## Syntax
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
playwright-cli run-code "async page => {
|
|
9
|
+
// Your Playwright code here
|
|
10
|
+
// Access page.context() for browser context operations
|
|
11
|
+
}"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
You can also load the function from a file:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
playwright-cli run-code --filename=./my-script.js
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
The code must be a single function expression, it is wrapped in `(...)` and evaluated.
|
|
22
|
+
import/export/require syntax is not supported.
|
|
23
|
+
|
|
24
|
+
## Geolocation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Grant geolocation permission and set location
|
|
28
|
+
playwright-cli run-code "async page => {
|
|
29
|
+
await page.context().grantPermissions(['geolocation']);
|
|
30
|
+
await page.context().setGeolocation({ latitude: 37.7749, longitude: -122.4194 });
|
|
31
|
+
}"
|
|
32
|
+
|
|
33
|
+
# Set location to London
|
|
34
|
+
playwright-cli run-code "async page => {
|
|
35
|
+
await page.context().grantPermissions(['geolocation']);
|
|
36
|
+
await page.context().setGeolocation({ latitude: 51.5074, longitude: -0.1278 });
|
|
37
|
+
}"
|
|
38
|
+
|
|
39
|
+
# Clear geolocation override
|
|
40
|
+
playwright-cli run-code "async page => {
|
|
41
|
+
await page.context().clearPermissions();
|
|
42
|
+
}"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Permissions
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Grant multiple permissions
|
|
49
|
+
playwright-cli run-code "async page => {
|
|
50
|
+
await page.context().grantPermissions([
|
|
51
|
+
'geolocation',
|
|
52
|
+
'notifications',
|
|
53
|
+
'camera',
|
|
54
|
+
'microphone'
|
|
55
|
+
]);
|
|
56
|
+
}"
|
|
57
|
+
|
|
58
|
+
# Grant permissions for specific origin
|
|
59
|
+
playwright-cli run-code "async page => {
|
|
60
|
+
await page.context().grantPermissions(['clipboard-read'], {
|
|
61
|
+
origin: 'https://example.com'
|
|
62
|
+
});
|
|
63
|
+
}"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Media Emulation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Emulate dark color scheme
|
|
70
|
+
playwright-cli run-code "async page => {
|
|
71
|
+
await page.emulateMedia({ colorScheme: 'dark' });
|
|
72
|
+
}"
|
|
73
|
+
|
|
74
|
+
# Emulate light color scheme
|
|
75
|
+
playwright-cli run-code "async page => {
|
|
76
|
+
await page.emulateMedia({ colorScheme: 'light' });
|
|
77
|
+
}"
|
|
78
|
+
|
|
79
|
+
# Emulate reduced motion
|
|
80
|
+
playwright-cli run-code "async page => {
|
|
81
|
+
await page.emulateMedia({ reducedMotion: 'reduce' });
|
|
82
|
+
}"
|
|
83
|
+
|
|
84
|
+
# Emulate print media
|
|
85
|
+
playwright-cli run-code "async page => {
|
|
86
|
+
await page.emulateMedia({ media: 'print' });
|
|
87
|
+
}"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Wait Strategies
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Wait for network idle
|
|
94
|
+
playwright-cli run-code "async page => {
|
|
95
|
+
await page.waitForLoadState('networkidle');
|
|
96
|
+
}"
|
|
97
|
+
|
|
98
|
+
# Wait for specific element
|
|
99
|
+
playwright-cli run-code "async page => {
|
|
100
|
+
await page.locator('.loading').waitFor({ state: 'hidden' });
|
|
101
|
+
}"
|
|
102
|
+
|
|
103
|
+
# Wait for function to return true
|
|
104
|
+
playwright-cli run-code "async page => {
|
|
105
|
+
await page.waitForFunction(() => window.appReady === true);
|
|
106
|
+
}"
|
|
107
|
+
|
|
108
|
+
# Wait with timeout
|
|
109
|
+
playwright-cli run-code "async page => {
|
|
110
|
+
await page.locator('.result').waitFor({ timeout: 10000 });
|
|
111
|
+
}"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Frames and Iframes
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Work with iframe
|
|
118
|
+
playwright-cli run-code "async page => {
|
|
119
|
+
const frame = page.locator('iframe#my-iframe').contentFrame();
|
|
120
|
+
await frame.locator('button').click();
|
|
121
|
+
}"
|
|
122
|
+
|
|
123
|
+
# Get all frames
|
|
124
|
+
playwright-cli run-code "async page => {
|
|
125
|
+
const frames = page.frames();
|
|
126
|
+
return frames.map(f => f.url());
|
|
127
|
+
}"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## File Downloads
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Handle file download
|
|
134
|
+
playwright-cli run-code "async page => {
|
|
135
|
+
const downloadPromise = page.waitForEvent('download');
|
|
136
|
+
await page.getByRole('link', { name: 'Download' }).click();
|
|
137
|
+
const download = await downloadPromise;
|
|
138
|
+
await download.saveAs('./downloaded-file.pdf');
|
|
139
|
+
return download.suggestedFilename();
|
|
140
|
+
}"
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Clipboard
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# Read clipboard (requires permission)
|
|
147
|
+
playwright-cli run-code "async page => {
|
|
148
|
+
await page.context().grantPermissions(['clipboard-read']);
|
|
149
|
+
return await page.evaluate(() => navigator.clipboard.readText());
|
|
150
|
+
}"
|
|
151
|
+
|
|
152
|
+
# Write to clipboard
|
|
153
|
+
playwright-cli run-code "async page => {
|
|
154
|
+
await page.evaluate(text => navigator.clipboard.writeText(text), 'Hello clipboard!');
|
|
155
|
+
}"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Page Information
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Get page title
|
|
162
|
+
playwright-cli run-code "async page => {
|
|
163
|
+
return await page.title();
|
|
164
|
+
}"
|
|
165
|
+
|
|
166
|
+
# Get current URL
|
|
167
|
+
playwright-cli run-code "async page => {
|
|
168
|
+
return page.url();
|
|
169
|
+
}"
|
|
170
|
+
|
|
171
|
+
# Get page content
|
|
172
|
+
playwright-cli run-code "async page => {
|
|
173
|
+
return await page.content();
|
|
174
|
+
}"
|
|
175
|
+
|
|
176
|
+
# Get viewport size
|
|
177
|
+
playwright-cli run-code "async page => {
|
|
178
|
+
return page.viewportSize();
|
|
179
|
+
}"
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## JavaScript Execution
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Execute JavaScript and return result
|
|
186
|
+
playwright-cli run-code "async page => {
|
|
187
|
+
return await page.evaluate(() => {
|
|
188
|
+
return {
|
|
189
|
+
userAgent: navigator.userAgent,
|
|
190
|
+
language: navigator.language,
|
|
191
|
+
cookiesEnabled: navigator.cookieEnabled
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
}"
|
|
195
|
+
|
|
196
|
+
# Pass arguments to evaluate
|
|
197
|
+
playwright-cli run-code "async page => {
|
|
198
|
+
const multiplier = 5;
|
|
199
|
+
return await page.evaluate(m => document.querySelectorAll('li').length * m, multiplier);
|
|
200
|
+
}"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Error Handling
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Try-catch in run-code
|
|
207
|
+
playwright-cli run-code "async page => {
|
|
208
|
+
try {
|
|
209
|
+
await page.getByRole('button', { name: 'Submit' }).click({ timeout: 1000 });
|
|
210
|
+
return 'clicked';
|
|
211
|
+
} catch (e) {
|
|
212
|
+
return 'element not found';
|
|
213
|
+
}
|
|
214
|
+
}"
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Complex Workflows
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# Login and save state
|
|
221
|
+
playwright-cli run-code "async page => {
|
|
222
|
+
await page.goto('https://example.com/login');
|
|
223
|
+
await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
|
|
224
|
+
await page.getByRole('textbox', { name: 'Password' }).fill('secret');
|
|
225
|
+
await page.getByRole('button', { name: 'Sign in' }).click();
|
|
226
|
+
await page.waitForURL('**/dashboard');
|
|
227
|
+
await page.context().storageState({ path: 'auth.json' });
|
|
228
|
+
return 'Login successful';
|
|
229
|
+
}"
|
|
230
|
+
|
|
231
|
+
# Scrape data from multiple pages
|
|
232
|
+
playwright-cli run-code "async page => {
|
|
233
|
+
const results = [];
|
|
234
|
+
for (let i = 1; i <= 3; i++) {
|
|
235
|
+
await page.goto(\`https://example.com/page/\${i}\`);
|
|
236
|
+
const items = await page.locator('.item').allTextContents();
|
|
237
|
+
results.push(...items);
|
|
238
|
+
}
|
|
239
|
+
return results;
|
|
240
|
+
}"
|
|
241
|
+
```
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Browser Session Management
|
|
2
|
+
|
|
3
|
+
Run multiple isolated browser sessions concurrently with state persistence.
|
|
4
|
+
|
|
5
|
+
## Named Browser Sessions
|
|
6
|
+
|
|
7
|
+
Use `-s` flag to isolate browser contexts:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Browser 1: Authentication flow
|
|
11
|
+
playwright-cli -s=auth open https://app.example.com/login
|
|
12
|
+
|
|
13
|
+
# Browser 2: Public browsing (separate cookies, storage)
|
|
14
|
+
playwright-cli -s=public open https://example.com
|
|
15
|
+
|
|
16
|
+
# Commands are isolated by browser session
|
|
17
|
+
playwright-cli -s=auth fill e1 "user@example.com"
|
|
18
|
+
playwright-cli -s=public snapshot
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Browser Session Isolation Properties
|
|
22
|
+
|
|
23
|
+
Each browser session has independent:
|
|
24
|
+
- Cookies
|
|
25
|
+
- LocalStorage / SessionStorage
|
|
26
|
+
- IndexedDB
|
|
27
|
+
- Cache
|
|
28
|
+
- Browsing history
|
|
29
|
+
- Open tabs
|
|
30
|
+
|
|
31
|
+
## Browser Session Commands
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# List all browser sessions
|
|
35
|
+
playwright-cli list
|
|
36
|
+
|
|
37
|
+
# Stop a browser session (close the browser)
|
|
38
|
+
playwright-cli close # stop the default browser
|
|
39
|
+
playwright-cli -s=mysession close # stop a named browser
|
|
40
|
+
|
|
41
|
+
# Stop all browser sessions
|
|
42
|
+
playwright-cli close-all
|
|
43
|
+
|
|
44
|
+
# Forcefully kill all daemon processes (for stale/zombie processes)
|
|
45
|
+
playwright-cli kill-all
|
|
46
|
+
|
|
47
|
+
# Delete browser session user data (profile directory)
|
|
48
|
+
playwright-cli delete-data # delete default browser data
|
|
49
|
+
playwright-cli -s=mysession delete-data # delete named browser data
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Environment Variable
|
|
53
|
+
|
|
54
|
+
Set a default browser session name via environment variable:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
export PLAYWRIGHT_CLI_SESSION="mysession"
|
|
58
|
+
playwright-cli open example.com # Uses "mysession" automatically
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Common Patterns
|
|
62
|
+
|
|
63
|
+
### Concurrent Scraping
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
#!/bin/bash
|
|
67
|
+
# Scrape multiple sites concurrently
|
|
68
|
+
|
|
69
|
+
# Start all browsers
|
|
70
|
+
playwright-cli -s=site1 open https://site1.com &
|
|
71
|
+
playwright-cli -s=site2 open https://site2.com &
|
|
72
|
+
playwright-cli -s=site3 open https://site3.com &
|
|
73
|
+
wait
|
|
74
|
+
|
|
75
|
+
# Take snapshots from each
|
|
76
|
+
playwright-cli -s=site1 snapshot
|
|
77
|
+
playwright-cli -s=site2 snapshot
|
|
78
|
+
playwright-cli -s=site3 snapshot
|
|
79
|
+
|
|
80
|
+
# Cleanup
|
|
81
|
+
playwright-cli close-all
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### A/B Testing Sessions
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Test different user experiences
|
|
88
|
+
playwright-cli -s=variant-a open "https://app.com?variant=a"
|
|
89
|
+
playwright-cli -s=variant-b open "https://app.com?variant=b"
|
|
90
|
+
|
|
91
|
+
# Compare
|
|
92
|
+
playwright-cli -s=variant-a screenshot
|
|
93
|
+
playwright-cli -s=variant-b screenshot
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Persistent Profile
|
|
97
|
+
|
|
98
|
+
By default, browser profile is kept in memory only. Use `--persistent` flag on `open` to persist the browser profile to disk:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Use persistent profile (auto-generated location)
|
|
102
|
+
playwright-cli open https://example.com --persistent
|
|
103
|
+
|
|
104
|
+
# Use persistent profile with custom directory
|
|
105
|
+
playwright-cli open https://example.com --profile=/path/to/profile
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Attaching to a Running Browser
|
|
109
|
+
|
|
110
|
+
Use `attach` to connect to a browser that is already running, instead of launching a new one.
|
|
111
|
+
|
|
112
|
+
### Attach by channel name
|
|
113
|
+
|
|
114
|
+
Connect to a running Chrome or Edge instance by its channel name. The browser must have remote debugging enabled — navigate to `chrome://inspect/#remote-debugging` in the target browser and check "Allow remote debugging for this browser instance".
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Attach to Chrome
|
|
118
|
+
playwright-cli attach --cdp=chrome
|
|
119
|
+
|
|
120
|
+
# Attach to Chrome Canary
|
|
121
|
+
playwright-cli attach --cdp=chrome-canary
|
|
122
|
+
|
|
123
|
+
# Attach to Microsoft Edge
|
|
124
|
+
playwright-cli attach --cdp=msedge
|
|
125
|
+
|
|
126
|
+
# Attach to Edge Dev
|
|
127
|
+
playwright-cli attach --cdp=msedge-dev
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Supported channels: `chrome`, `chrome-beta`, `chrome-dev`, `chrome-canary`, `msedge`, `msedge-beta`, `msedge-dev`, `msedge-canary`.
|
|
131
|
+
|
|
132
|
+
When `--session` is not provided, the session is named after the channel (e.g. `--cdp=msedge` creates a session called `msedge`), so parallel attaches to Chrome and Edge don't collide on `default`. Pass `--session=<name>` to override.
|
|
133
|
+
|
|
134
|
+
### Attach via CDP endpoint
|
|
135
|
+
|
|
136
|
+
Connect to a browser that exposes a Chrome DevTools Protocol endpoint:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
playwright-cli attach --cdp=http://localhost:9222
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Attach via browser extension
|
|
143
|
+
|
|
144
|
+
Connect to a browser with the Playwright extension installed:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
playwright-cli attach --extension
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Detach
|
|
151
|
+
|
|
152
|
+
Tear down an attached session without affecting the external browser:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Detach the default attached session
|
|
156
|
+
playwright-cli detach
|
|
157
|
+
|
|
158
|
+
# Detach a specific attached session
|
|
159
|
+
playwright-cli -s=msedge detach
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`detach` only works on sessions created via `attach`. For sessions created via `open`, use `close`.
|
|
163
|
+
|
|
164
|
+
## Default Browser Session
|
|
165
|
+
|
|
166
|
+
When `-s` is omitted, commands use the default browser session:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# These use the same default browser session
|
|
170
|
+
playwright-cli open https://example.com
|
|
171
|
+
playwright-cli snapshot
|
|
172
|
+
playwright-cli close # Stops default browser
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Browser Session Configuration
|
|
176
|
+
|
|
177
|
+
Configure a browser session with specific settings when opening:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# Open with config file
|
|
181
|
+
playwright-cli open https://example.com --config=.playwright/my-cli.json
|
|
182
|
+
|
|
183
|
+
# Open with specific browser
|
|
184
|
+
playwright-cli open https://example.com --browser=firefox
|
|
185
|
+
|
|
186
|
+
# Open in headed mode
|
|
187
|
+
playwright-cli open https://example.com --headed
|
|
188
|
+
|
|
189
|
+
# Open with persistent profile
|
|
190
|
+
playwright-cli open https://example.com --persistent
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Best Practices
|
|
194
|
+
|
|
195
|
+
### 1. Name Browser Sessions Semantically
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# GOOD: Clear purpose
|
|
199
|
+
playwright-cli -s=github-auth open https://github.com
|
|
200
|
+
playwright-cli -s=docs-scrape open https://docs.example.com
|
|
201
|
+
|
|
202
|
+
# AVOID: Generic names
|
|
203
|
+
playwright-cli -s=s1 open https://github.com
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 2. Always Clean Up
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# Stop browsers when done
|
|
210
|
+
playwright-cli -s=auth close
|
|
211
|
+
playwright-cli -s=scrape close
|
|
212
|
+
|
|
213
|
+
# Or stop all at once
|
|
214
|
+
playwright-cli close-all
|
|
215
|
+
|
|
216
|
+
# If browsers become unresponsive or zombie processes remain
|
|
217
|
+
playwright-cli kill-all
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 3. Delete Stale Browser Data
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
# Remove old browser data to free disk space
|
|
224
|
+
playwright-cli -s=oldsession delete-data
|
|
225
|
+
```
|