playwright-test-agent 0.1.9 → 0.2.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/package.json
CHANGED
|
@@ -5,25 +5,26 @@ description: Use first when a user asks to investigate or test a website, browse
|
|
|
5
5
|
|
|
6
6
|
# Playwright Test Agent
|
|
7
7
|
|
|
8
|
-
Use Planner -> Generator -> Healer for durable tests. `AGENTS.md` or `CLAUDE.md` defines the platform-specific role routing.
|
|
8
|
+
Use Planner -> Generator -> Healer for durable tests. `AGENTS.md` or `CLAUDE.md` defines the platform-specific role routing. The role that owns the current phase uses `playwright-cli`; the parent does not perform another role's browser work.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Required phase handoff
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
1. Planner investigates the application and saves a Markdown plan under `specs/`.
|
|
13
|
+
2. The parent presents that plan and waits for user confirmation.
|
|
14
|
+
3. Generator validates the confirmed plan and writes executable tests.
|
|
15
|
+
4. Healer runs only for failing generated tests.
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
playwright-cli open <deployed-url>
|
|
16
|
-
```
|
|
17
|
+
On Claude Code, the parent must start `playwright-test-planner`; only that Planner may open the website. The parent must not call `playwright-cli`, Chrome DevTools, browser MCP tools, or another browser integration. On Codex, the main agent does not spawn a Playwright subagent; it explicitly assumes one phase at a time, and may call CLI only while acting in that phase. Preserve the official Playwright Test MCP configuration and role tools; CLI is the preferred live-browser path and prevents missing MCP tools from blocking the workflow.
|
|
17
18
|
|
|
18
|
-
Before
|
|
19
|
+
Before Planner, the parent may read relevant local project information to understand routes, requirements, fixtures, and constraints. It may ask for information that is necessary or could materially change the test purpose, scope, assertions, access, or safety, such as the deployed URL, account or role, expected behavior, target environment, allowed data mutations, and authorization boundary. Keep this preparation focused: do not locate a seed file or turn config, test-directory, agent-definition, fixture, or generated-file discovery into a prerequisite.
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
If the available context is sufficient, start/enter Planner without further confirmation. During exploration, pause when required information is missing, incorrect, or contradictory, including credentials, URL, role, prerequisites, expected behavior that changes assertions, or authorization for a consequential action. Ask the user for the specific correction, then resume or restart Planner with the answer and blocking observation. Do not guess credentials, probe nearby environments, bypass access controls, or wander through unrelated pages.
|
|
21
22
|
|
|
22
23
|
Keep credentials and tokens in environment variables or ignored secret files. Never copy them into plans, tests, screenshots, evidence, or chat.
|
|
23
24
|
|
|
24
25
|
## Planner
|
|
25
26
|
|
|
26
|
-
Planner
|
|
27
|
+
Planner—not the parent—opens the supplied URL with `playwright-cli open <deployed-url>`, investigates the application, and saves a human-readable Markdown plan under `specs/`. Once the parent has supplied the objective, URL, access information, relevant project context, and constraints, Planner's first browser action must be that CLI command. It then uses compact `snapshot` or `find` output and refs for interaction. A seed is not a prerequisite and must not be located before exploration.
|
|
27
28
|
|
|
28
29
|
The plan contains prerequisites, test data, independent scenarios, steps, observable expected results, exclusions, and intended output files. Reconnaissance must not mutate durable/shared data or perform consequential actions unless authorized.
|
|
29
30
|
|
|
@@ -31,13 +32,13 @@ Show the scenario list and exclusions to the user. Generator starts only after c
|
|
|
31
32
|
|
|
32
33
|
## Generator
|
|
33
34
|
|
|
34
|
-
Generator converts the confirmed plan into executable tests.
|
|
35
|
+
Generator starts only after confirmation and converts the confirmed plan into executable tests. Generator—not the parent—uses `playwright-cli` to validate flows, locators, and assertions, then writes the tests directly. Generate only confirmed scenarios; prefer independent tests, semantic locators, explicit assertions, and environment-based secrets.
|
|
35
36
|
|
|
36
37
|
For API-only scenarios, use Playwright `APIRequestContext` directly and assert status, headers, schema, stable business invariants, and safe mutation cleanup.
|
|
37
38
|
|
|
38
39
|
## Healer
|
|
39
40
|
|
|
40
|
-
Use Healer only for failures.
|
|
41
|
+
Use Healer only for failures. Healer—not the parent—runs the failing test with `npx playwright test`, reproduces and inspects the UI with `playwright-cli`, applies justified test-side changes, and reruns within guardrails.
|
|
41
42
|
|
|
42
43
|
Do not weaken assertions, add arbitrary sleeps, retry blindly, or skip merely to pass. If behavior conflicts with the confirmed plan, preserve evidence and ask whether it is a regression or intended change. Classify unresolved failures as application defect, test defect, environment/data problem, or product decision.
|
|
43
44
|
|
|
@@ -13,24 +13,40 @@ const cliFirstInstructions = (role) => `${ROLE_BLOCK_START}
|
|
|
13
13
|
|
|
14
14
|
## Browser tool priority
|
|
15
15
|
|
|
16
|
-
Use the installed \`playwright-cli\` command as the primary browser interface. Read the globally installed \`playwright-cli\` skill when available. Start or attach a session with \`playwright-cli open\`/\`attach\`, navigate with \`goto\`, inspect compact state with \`snapshot\`, and interact through refs from the latest snapshot. Prefer \`snapshot\` and \`find\` over screenshots. Keep credentials in environment variables or ignored files and never print them.
|
|
16
|
+
Use the installed \`playwright-cli\` command as the primary browser interface for this role. Read the globally installed \`playwright-cli\` skill when available. Start or attach a session with \`playwright-cli open\`/\`attach\`, navigate with \`goto\`, inspect compact state with \`snapshot\`, and interact through refs from the latest snapshot. Prefer \`snapshot\` and \`find\` over screenshots. Keep credentials in environment variables or ignored files and never print them.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Keep the official Playwright Test MCP configuration and tools generated for this role; do not remove or disable them. Prefer CLI for live page interaction and use it when those MCP tools are unavailable, so missing \`planner_*\`, \`generator_*\`, \`test_*\`, or \`browser_*\` tools must not block the phase. Do not call Chrome DevTools or an unrelated browser integration, and do not spawn a nested or same-role agent.
|
|
19
19
|
|
|
20
|
-
${role === 'planner' ? 'FAST START:
|
|
20
|
+
${role === 'planner' ? 'FAST START: you are the Planner. The parent may pass relevant local-project context and answers gathered before this phase. When the request contains the test objective, deployed URL, and any information required to access the target, your first browser action must be `playwright-cli open <url>`; do not call `planner_setup_page` or any other browser/MCP action before this CLI open. After the session is open, use compact CLI `snapshot`/`find` output for exploration; MCP tools remain available as an optional supplement. Do not wait for the parent agent to open a browser, and do not first locate or read a seed file, Playwright config, test directory, agent definition, source tree, fixtures, or existing tests. Ask only when the supplied information is still missing, incorrect, contradictory, or exploration reaches a real blocker such as required credentials, ambiguous expected behavior that changes assertions, or authorization for a consequential action. Save the completed Markdown test plan directly under `specs/` using filesystem tools or the available planner save tool.' : ''}${role === 'generator' ? 'You are the Generator. Start only after the parent agent confirms the plan. Begin live validation with `playwright-cli open`/`attach` and use CLI snapshots/find to verify the confirmed plan; MCP setup and browser tools remain optional. Then write executable Playwright test files directly with filesystem tools or the available generator write tool.' : ''}${role === 'healer' ? 'You are the Healer. Run failures with `npx playwright test`, begin UI diagnosis with `playwright-cli open`/`attach`, and use CLI snapshots/find to inspect and reproduce the current UI; MCP tools remain optional. Patch the tests directly and rerun within the healer guardrails.' : ''}
|
|
21
21
|
|
|
22
22
|
${ROLE_BLOCK_END}`;
|
|
23
23
|
const CODEX_INSTRUCTIONS = `${BLOCK_START}
|
|
24
24
|
## Playwright Test Agent
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Codex routing is mandatory for website, browser workflow, HTTP API, or application-feature testing:
|
|
27
|
+
|
|
28
|
+
1. Load \`.agents/skills/playwright-test-agent/SKILL.md\`.
|
|
29
|
+
2. Before Planner, the main agent may read relevant local project information and ask for information that materially affects the test, such as the deployed URL, account or role, expected behavior, environment, and authorization boundary. Do not perform a seed/config/generated-file audit or open the website during preparation.
|
|
30
|
+
3. Do not start Playwright subagents. Once the required context is available, the main agent explicitly assumes the Planner role in this session.
|
|
31
|
+
4. Planner's first live browser action is \`playwright-cli open <url>\`. Prefer CLI while preserving the generated Playwright Test MCP configuration and tools. Do not call Chrome DevTools or an unrelated browser integration.
|
|
32
|
+
5. After Planner saves the plan, show it to the user and wait for confirmation. Then assume Generator; use Healer only for failing generated tests.
|
|
33
|
+
|
|
34
|
+
Ask only for information that is necessary or could materially change scope, assertions, access, or safety. Do not guess or create nested agents.
|
|
27
35
|
|
|
28
36
|
${BLOCK_END}`;
|
|
29
37
|
|
|
30
38
|
const CLAUDE_INSTRUCTIONS = `${BLOCK_START}
|
|
31
39
|
## Playwright Test Agent
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
Claude Code routing is mandatory for website, browser workflow, HTTP API, or application-feature testing:
|
|
42
|
+
|
|
43
|
+
1. Load \`.claude/skills/playwright-test-agent/SKILL.md\`.
|
|
44
|
+
2. Before starting Planner, the main agent may read relevant local project information and ask for information that materially affects the test, such as the deployed URL, account or role, expected behavior, environment, and authorization boundary. Do not perform a seed/config/generated-file audit.
|
|
45
|
+
3. Once the required context is available, directly start \`playwright-test-planner\` with the objective, deployed URL, supplied access information, relevant project context, and constraints. The main agent must not open or inspect the website itself and must not call \`playwright-cli\`, Chrome DevTools, browser MCP tools, or another browser integration.
|
|
46
|
+
4. Planner opens and investigates the website with \`playwright-cli\` and saves the Markdown plan. After Planner returns, show the plan to the user and wait for confirmation.
|
|
47
|
+
5. Only after confirmation start \`playwright-test-generator\`. Start \`playwright-test-healer\` only for failing generated tests.
|
|
48
|
+
|
|
49
|
+
Start each role directly and never create a nested or same-role intermediary. Do not locate a seed file or make setup-file discovery a prerequisite to Planner. If exploration finds missing, incorrect, or contradictory required information, let Planner pause and return the precise question; after the user answers, start or resume Planner with that answer and the blocking observation. Do not guess.
|
|
34
50
|
|
|
35
51
|
${BLOCK_END}`;
|
|
36
52
|
|
|
@@ -141,11 +157,11 @@ function patchClaudeRole(source, role) {
|
|
|
141
157
|
const remainder = header.slice(blockStart);
|
|
142
158
|
const nextKey = remainder.search(/\r?\n(?=[A-Za-z0-9_-]+:\s*)/);
|
|
143
159
|
const blockEnd = nextKey === -1 ? header.length : blockStart + nextKey;
|
|
144
|
-
|
|
160
|
+
let toolsBlock = header.slice(blockStart, blockEnd);
|
|
145
161
|
if (!/^\s*-\s+Bash\s*$/m.test(toolsBlock)) {
|
|
146
|
-
|
|
147
|
-
header.slice(blockStart);
|
|
162
|
+
toolsBlock = `\n - Bash${toolsBlock}`;
|
|
148
163
|
}
|
|
164
|
+
header = header.slice(0, blockStart) + toolsBlock + header.slice(blockEnd);
|
|
149
165
|
} else {
|
|
150
166
|
header = `${header.trimEnd()}\ntools: Bash`;
|
|
151
167
|
}
|
|
@@ -171,6 +187,61 @@ async function configureCliFirstRoles(projectDir) {
|
|
|
171
187
|
}
|
|
172
188
|
}
|
|
173
189
|
|
|
190
|
+
function escapeRegExp(value) {
|
|
191
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function upsertTomlSection(source, section, settings) {
|
|
195
|
+
const headerPattern = new RegExp(`^\\[${escapeRegExp(section)}\\][ \\t]*$`, 'm');
|
|
196
|
+
const header = source.match(headerPattern);
|
|
197
|
+
|
|
198
|
+
if (!header) {
|
|
199
|
+
const body = Object.entries(settings).map(([key, value]) => `${key} = ${value}`).join('\n');
|
|
200
|
+
const separator = source.length === 0 ? '' : source.endsWith('\n') ? '\n' : '\n\n';
|
|
201
|
+
return `${source}${separator}[${section}]\n${body}\n`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const bodyStart = header.index + header[0].length;
|
|
205
|
+
const remainder = source.slice(bodyStart);
|
|
206
|
+
const nextHeader = remainder.search(/\r?\n(?=\[[^\]]+\][ \\t]*(?:\r?\n|$))/);
|
|
207
|
+
const bodyEnd = nextHeader === -1 ? source.length : bodyStart + nextHeader;
|
|
208
|
+
let body = source.slice(bodyStart, bodyEnd);
|
|
209
|
+
|
|
210
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
211
|
+
const settingPattern = new RegExp(`(^|\\n)${escapeRegExp(key)}[ \\t]*=[^\\r\\n]*`);
|
|
212
|
+
if (settingPattern.test(body)) {
|
|
213
|
+
body = body.replace(settingPattern, `$1${key} = ${value}`);
|
|
214
|
+
} else {
|
|
215
|
+
body = `${body.trimEnd()}\n${key} = ${value}\n`;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return source.slice(0, bodyStart) + body + source.slice(bodyEnd);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async function configureCodexMcp(projectDir) {
|
|
223
|
+
const codexDir = path.join(projectDir, '.codex');
|
|
224
|
+
const file = path.join(codexDir, 'config.toml');
|
|
225
|
+
await mkdir(codexDir, { recursive: true });
|
|
226
|
+
let source = await exists(file) ? await readFile(file, 'utf8') : '';
|
|
227
|
+
const command = process.platform === 'win32' ? '"cmd"' : '"npx"';
|
|
228
|
+
const args = process.platform === 'win32'
|
|
229
|
+
? '["/d", "/s", "/c", "npx", "--no-install", "playwright", "run-test-mcp-server"]'
|
|
230
|
+
: '["--no-install", "playwright", "run-test-mcp-server"]';
|
|
231
|
+
|
|
232
|
+
source = upsertTomlSection(source, 'mcp_servers.playwright-test', {
|
|
233
|
+
command,
|
|
234
|
+
args,
|
|
235
|
+
cwd: '"."',
|
|
236
|
+
enabled: 'true',
|
|
237
|
+
default_tools_approval_mode: '"approve"',
|
|
238
|
+
});
|
|
239
|
+
source = upsertTomlSection(source, 'mcp_servers.playwright-test.env', {
|
|
240
|
+
PLAYWRIGHT_MCP_OUTPUT_DIR: '".playwright-evidence/mcp"',
|
|
241
|
+
});
|
|
242
|
+
await writeFile(file, source, 'utf8');
|
|
243
|
+
}
|
|
244
|
+
|
|
174
245
|
async function installPlaywrightCli(projectDir, run) {
|
|
175
246
|
await run(projectDir, 'npm', ['install', '-g', '@playwright/cli@latest']);
|
|
176
247
|
await run(projectDir, 'playwright-cli', ['install', '--skills=agents', '--global']);
|
|
@@ -222,33 +293,7 @@ async function disableTraceScreenshots(projectDir) {
|
|
|
222
293
|
}
|
|
223
294
|
}
|
|
224
295
|
|
|
225
|
-
async function
|
|
226
|
-
const file = path.join(projectDir, '.mcp.json');
|
|
227
|
-
if (!await exists(file)) return;
|
|
228
|
-
const config = JSON.parse(await readFile(file, 'utf8'));
|
|
229
|
-
const server = config.mcpServers?.['playwright-test'];
|
|
230
|
-
if (!server) return;
|
|
231
|
-
server.env = {
|
|
232
|
-
...(server.env ?? {}),
|
|
233
|
-
PLAYWRIGHT_MCP_OUTPUT_DIR: '.playwright-evidence/mcp',
|
|
234
|
-
};
|
|
235
|
-
await writeFile(file, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
async function configureCodexAgents(projectDir) {
|
|
239
|
-
for (const name of ['planner', 'generator', 'healer']) {
|
|
240
|
-
const file = path.join(projectDir, '.codex', 'agents', `playwright_test_${name}.toml`);
|
|
241
|
-
if (!await exists(file)) continue;
|
|
242
|
-
let source = await readFile(file, 'utf8');
|
|
243
|
-
if (!source.includes('[mcp_servers.playwright-test.env]')) {
|
|
244
|
-
source = `${source.trimEnd()}\n\n[mcp_servers.playwright-test.env]\n` +
|
|
245
|
-
'PLAYWRIGHT_MCP_OUTPUT_DIR = ".playwright-evidence/mcp"\n';
|
|
246
|
-
await writeFile(file, source, 'utf8');
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
async function initializePlaywright(projectDir, run) {
|
|
296
|
+
async function initializePlaywright(projectDir, run) {
|
|
252
297
|
const configPath = path.join(projectDir, 'playwright.config.ts');
|
|
253
298
|
if (!await exists(configPath)) {
|
|
254
299
|
await run(projectDir, 'npm', [
|
|
@@ -272,12 +317,11 @@ async function initializePlaywright(projectDir, run) {
|
|
|
272
317
|
await disableTraceScreenshots(projectDir);
|
|
273
318
|
|
|
274
319
|
await run(projectDir, 'npx', ['--no-install', 'playwright', 'init-agents', '--loop=codex']);
|
|
275
|
-
await run(projectDir, 'npx', ['--no-install', 'playwright', 'init-agents', '--loop=claude']);
|
|
276
|
-
await mkdir(path.join(projectDir, '.playwright-evidence', 'mcp'), { recursive: true });
|
|
277
|
-
await
|
|
278
|
-
await configureCodexAgents(projectDir);
|
|
320
|
+
await run(projectDir, 'npx', ['--no-install', 'playwright', 'init-agents', '--loop=claude']);
|
|
321
|
+
await mkdir(path.join(projectDir, '.playwright-evidence', 'mcp'), { recursive: true });
|
|
322
|
+
await configureCodexMcp(projectDir);
|
|
279
323
|
await configureCliFirstRoles(projectDir);
|
|
280
|
-
}
|
|
324
|
+
}
|
|
281
325
|
|
|
282
326
|
async function runStage(name, action) {
|
|
283
327
|
process.stdout.write(`[playwright-test-agent] ${name}...\n`);
|