playwright-test-agent 0.1.1 → 0.1.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-test-agent",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Initialize Playwright Test agents and install the playwright-test-agent skill.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -5,7 +5,33 @@ description: Use first when a user asks to test a website, browser workflow, HTT
5
5
 
6
6
  # Playwright Test Agent
7
7
 
8
- Use Playwright Test for durable automation. Browser tests use Playwright's official planner, generator, and healer subagents. Pure HTTP API tests may be written directly with Playwright `APIRequestContext` without those subagents.
8
+ Use Playwright Test for durable automation. The main agent orchestrates Playwright's official planner, generator, and healer subagents instead of replacing their work with ad hoc browser exploration. Pure HTTP API tests may be written directly with Playwright `APIRequestContext` without those subagents.
9
+
10
+ This file is the single source of truth for the testing workflow. Project-level `AGENTS.md` and `CLAUDE.md` only force this skill to be loaded and name the platform-specific subagents; do not duplicate or infer the detailed workflow from those routing files.
11
+
12
+ ## Platform agent names
13
+
14
+ | Role | Codex | Claude Code |
15
+ |---|---|---|
16
+ | Planner | `playwright_test_planner` | `playwright-test-planner` |
17
+ | Generator | `playwright_test_generator` | `playwright-test-generator` |
18
+ | Healer | `playwright_test_healer` | `playwright-test-healer` |
19
+
20
+ Use the names for the active platform. The role names below refer to these mapped agents.
21
+
22
+ ## Agent responsibilities
23
+
24
+ - **Main agent:** Own the user conversation, gather the minimum entry information, locate the default seed generated by `playwright init-agents`, dispatch each subagent with that seed, present the plan for confirmation, and report final results. It must not ask the user to provide a seed or investigate UI details itself when the planner can discover them.
25
+ - **Planner:** Run the generated seed to establish page context, global setup, dependencies, fixtures, and hooks. Explore the deployed application for the requested scenarios and user flows, compare observations with the request and optional PRD, and save a precise human-readable Markdown plan under `specs/`. It does not generate the formal test files.
26
+ - **Generator:** Read the complete user-confirmed Markdown plan and the same generated seed, execute each scenario to validate locators and assertions against the live application, and generate executable Playwright tests under the configured test directory. It must not invent unconfirmed scenarios or expected behavior.
27
+ - **Healer:** Run the failing test, replay its steps, inspect the current UI, propose and apply test-side patches, and rerun until the test passes or a guardrail stops the loop. It must report a likely broken product, environment/data problem, or plan conflict instead of weakening assertions merely to obtain a pass.
28
+
29
+ For UI testing, keep these responsibilities and sequence:
30
+
31
+ ```text
32
+ request + deployed URL -> locate generated seed -> planner -> user confirms plan
33
+ -> generator -> healer for failures -> final report
34
+ ```
9
35
 
10
36
  ## Initialize once per project
11
37
 
@@ -24,23 +50,29 @@ npx playwright init-agents --loop=claude
24
50
 
25
51
  It uses the project-local Playwright command. Never install a global/additional Playwright CLI or run `playwright init-skills`.
26
52
 
53
+ `playwright init-agents` also creates the project's default `seed.spec.ts`. Its directory follows the selected Playwright project's `testDir`, so it may be under `playwright-tests/`, `e2e/`, `tests/`, or another configured directory. Do not hardcode the path. Locate it from `playwright.config.*`, the generated agent definitions, or the filesystem before invoking planner or generator.
54
+
27
55
  ## Understand the request
28
56
 
29
- Before testing, inspect the target project for relevant source, routes/API clients, environment examples, existing tests, and run instructions. The project may be empty or may contain no useful application context; in that case, do not keep searching the filesystem or invent missing details. Use the user's description and the live target as the available evidence.
57
+ Before testing, briefly inspect the target project for relevant source, routes/API clients, environment examples, existing tests, fixtures, the generated seed, and run instructions. The project may otherwise be empty or contain no useful application context; in that case, do not keep searching the filesystem or invent missing details. Use the user's description, generated seed, and live target as the available evidence.
30
58
 
31
- Establish the objective, reachable environment/base URL, allowed side effects, authentication/roles, required test data/variables, and observable success criteria before invoking the planner. Ask the user for any material fact that cannot be verified from the project or target application.
59
+ Invoke the Planner as soon as the user has supplied a UI test objective and a deployed base URL. For example, "test this project's login feature" plus its deployment URL is sufficient: the Planner, not the main agent, investigates the login page, fields, controls, navigation, and observable outcomes. Do not delay Planner dispatch by asking for UI facts it can safely discover from the live application.
32
60
 
33
- If reconnaissance shows that provided information is missing, invalid, stale, or contradictory—for example, the URL is unreachable, a page or control does not exist, credentials fail, the observed role differs, a required variable is absent, or the application behavior conflicts with the stated workflow—stop exploring. Report the exact mismatch without exposing secrets and ask the user to correct or complete the information. Do not repeatedly try nearby URLs, guess credentials, wander through unrelated pages, or invoke the planner while blocked. Resume reconnaissance and invoke the planner only after the user supplies enough corrected information.
61
+ Pass the planner the exact objective, deployed URL, generated seed path, known authentication/roles, allowed side effects, supplied test data, and relevant project or PRD context. The seed is produced by initialization, not supplied by the user. It may remain the default page-context seed or be customized for project fixtures, global setup, dependencies, or authenticated context. Credentials are required before attempting an authenticated-only flow, but not merely to investigate a publicly reachable login page.
62
+
63
+ If no seed can be located after initialization, treat the Playwright agent setup as incomplete. Check the configured test directory and generated agent definitions, then rerun `npx playwright-test-agent init` when regeneration is needed. Do not ask the user to author a seed, invent an arbitrary path, or continue to planner without the initialized project context.
64
+
65
+ If planner reconnaissance shows that information is missing, invalid, stale, or contradictory—for example, the URL is unreachable, a page or control does not exist, credentials fail, the observed role differs, a required variable is absent, or application behavior conflicts with the request—stop that planning attempt. Report the exact mismatch without exposing secrets and ask the user to correct or complete it. Do not repeatedly try nearby URLs, guess credentials, wander through unrelated pages, or substitute the main agent's own exploration. Resume with the planner only after the user supplies enough corrected information.
34
66
 
35
67
  Never put credentials or tokens in plans, source, screenshots, reports, or chat output. Use environment variables or an ignored secret file.
36
68
 
37
69
  ## Plan and confirm
38
70
 
39
- Always save a plan to `specs/<feature>.plan.md` before generating or running tests. Include prerequisites, seed, test data, independent scenarios, steps or requests, expected observable results, and output test files.
71
+ Always have the planner save its human-readable Markdown plan under `specs/` before invoking the generator. Include prerequisites, the generated seed path, test data, independent scenarios, steps or requests, expected observable results, and intended output test files.
40
72
 
41
- For UI work, invoke `playwright_test_planner` only after the required project/user information has been checked and no known mismatch is blocking exploration. Have it inspect the live application and save the plan. Reconnaissance must not create, delete, submit, purchase, message, or otherwise mutate durable/shared data without authorization.
73
+ For UI work, invoke the Planner once the objective, deployed base URL, and generated seed path are available and no known mismatch already blocks access. Explicitly name the seed in its prompt and provide an optional PRD only when one is relevant. The Planner runs the seed to perform global setup, dependencies, fixtures, and hooks, then uses its ready page context to inspect the live application. Reconnaissance must not create, delete, submit, purchase, message, or otherwise mutate durable/shared data without authorization.
42
74
 
43
- If the planner discovers a new missing or incorrect prerequisite, stop that planning attempt, summarize what was observed, and ask the user for clarification. Continue with the planner only after the prerequisite is resolved; do not let the planner keep exploring around the missing information.
75
+ If the planner discovers a new missing or incorrect prerequisite, the main agent stops that planning attempt, summarizes what was observed, and asks the user for clarification. Continue or reinvoke the planner only after the prerequisite is resolved; do not let it keep exploring around missing information.
44
76
 
45
77
  Choose relevant positive, negative, empty, invalid, boundary, permission, persistence, and error scenarios. For login, normally consider valid credentials, empty username, empty password, both empty, wrong password, and unknown user; add MFA, lockout, recovery, or remember-me only when in scope.
46
78
 
@@ -48,11 +80,13 @@ Show the complete scenario list and exclusions to the user. Ask whether it is co
48
80
 
49
81
  ## Generate and run
50
82
 
51
- For confirmed UI scenarios, invoke `playwright_test_generator` once for the complete confirmed plan (or the complete selected set of scenarios), passing the exact plan content, seed, and destination under `playwright-tests/`. The generator processes the scenarios in plan order in that single invocation; its internal per-scenario setup does not mean starting a new generator agent for each scenario. Require one independent test per file, semantic locators, an assertion for every expected result, and environment-based secrets.
83
+ For confirmed UI scenarios, invoke the Generator once for the complete confirmed plan (or complete selected scenario set), explicitly naming the Markdown plan and the same generated seed; use the configured Playwright test directory for generated tests. The Generator executes scenarios against the live application to validate locators and assertions while generating. Its internal per-scenario setup does not mean starting a new Generator agent for every scenario. Require one independent test per file, semantic locators, an assertion for every expected result, and environment-based secrets.
52
84
 
53
85
  For confirmed API-only scenarios, write `APIRequestContext` tests directly under `playwright-tests/`. Assert status, headers, schema, and stable business invariants; define safe setup/cleanup for mutations.
54
86
 
55
- Run the generated tests with the project-local command. On failure, use `playwright_test_healer` one failure at a time for UI tests; API failures may be diagnosed directly. If observed product behavior conflicts with the confirmed plan, ask whether it is a regression or intended change. Do not weaken assertions, add sleeps/`networkidle`, retry blindly, or skip/fixme tests merely to get green.
87
+ After generation, invoke the Healer with one failing UI test name at a time. The Healer runs the test, replays the failing steps, inspects the current UI for the equivalent element or flow, proposes a patch such as a locator, synchronization, or test-data repair, and reruns until it passes or a guardrail stops the loop. API failures may be diagnosed directly.
88
+
89
+ If observed product behavior conflicts with the confirmed plan, report the conflict and ask whether it is a regression or intended change. Do not weaken assertions, add arbitrary sleeps/`networkidle`, retry blindly, or skip/fixme tests merely to get green. If the healer concludes the feature is broken, preserve the failure evidence and report it as an application defect rather than treating a skipped test as success.
56
90
 
57
91
  ## Preserve evidence
58
92
 
@@ -7,10 +7,24 @@ import { fileURLToPath } from 'node:url';
7
7
 
8
8
  const BLOCK_START = '<!-- playwright-test-agent:start -->';
9
9
  const BLOCK_END = '<!-- playwright-test-agent:end -->';
10
- const PROJECT_INSTRUCTIONS = `${BLOCK_START}
10
+ const CODEX_INSTRUCTIONS = `${BLOCK_START}
11
11
  ## Playwright Test Agent
12
12
 
13
- When asked to test a website, browser workflow, HTTP API, or application feature, load and follow the project-installed \`playwright-test-agent\` skill first. For UI tests, use its Playwright Test planner, generator, and healer workflow instead of ad hoc browser automation. Keep its confirmation, credential, side-effect, and evidence rules in force.
13
+ For any website, browser workflow, HTTP API, or application-feature testing request, load and follow \`.agents/skills/playwright-test-agent/SKILL.md\` before planning or using browser tools. This skill has priority over ad hoc browser automation.
14
+
15
+ For UI testing, the Codex subagents are \`playwright_test_planner\`, \`playwright_test_generator\`, and \`playwright_test_healer\`. When the user provides a UI test objective and deployed URL, the main agent must start \`playwright_test_planner\` to investigate the live page; it must not replace Planner work with its own ad hoc browser exploration.
16
+
17
+ If Planner reports that required test information is missing, invalid, or inconsistent, stop that planning attempt and ask the user for the specific missing information. After the user responds, start \`playwright_test_planner\` again with the corrected information and the previous blocking observation. Do not continue guessing or exploring around the blocker.
18
+ ${BLOCK_END}`;
19
+
20
+ const CLAUDE_INSTRUCTIONS = `${BLOCK_START}
21
+ ## Playwright Test Agent
22
+
23
+ For any website, browser workflow, HTTP API, or application-feature testing request, load and follow \`.claude/skills/playwright-test-agent/SKILL.md\` before planning or using browser tools. This skill has priority over ad hoc browser automation.
24
+
25
+ For UI testing, the Claude Code subagents are \`playwright-test-planner\`, \`playwright-test-generator\`, and \`playwright-test-healer\`. When the user provides a UI test objective and deployed URL, the main agent must start \`playwright-test-planner\` to investigate the live page; it must not replace Planner work with its own ad hoc browser exploration.
26
+
27
+ If Planner reports that required test information is missing, invalid, or inconsistent, stop that planning attempt and ask the user for the specific missing information. After the user responds, start \`playwright-test-planner\` again with the corrected information and the previous blocking observation. Do not continue guessing or exploring around the blocker.
14
28
  ${BLOCK_END}`;
15
29
 
16
30
  const exists = async (file) => {
@@ -35,7 +49,7 @@ const defaultRun = (projectDir, command, args) => new Promise((resolve, reject)
35
49
  : reject(new Error(`${command} ${args.join(' ')} exited with ${code}`)));
36
50
  });
37
51
 
38
- function withManagedBlock(source) {
52
+ function withManagedBlock(source, managedBlock) {
39
53
  const start = source.indexOf(BLOCK_START);
40
54
  const end = source.indexOf(BLOCK_END);
41
55
 
@@ -44,12 +58,12 @@ function withManagedBlock(source) {
44
58
  }
45
59
 
46
60
  if (start !== -1) {
47
- return source.slice(0, start) + PROJECT_INSTRUCTIONS + source.slice(end + BLOCK_END.length);
61
+ return source.slice(0, start) + managedBlock + source.slice(end + BLOCK_END.length);
48
62
  }
49
63
 
50
- if (source.length === 0) return `${PROJECT_INSTRUCTIONS}\n`;
64
+ if (source.length === 0) return `${managedBlock}\n`;
51
65
  const separator = source.endsWith('\n') ? '\n' : '\n\n';
52
- return `${source}${separator}${PROJECT_INSTRUCTIONS}\n`;
66
+ return `${source}${separator}${managedBlock}\n`;
53
67
  }
54
68
 
55
69
  async function installSkill(projectDir, skillSourceDir) {
@@ -61,10 +75,14 @@ async function installSkill(projectDir, skillSourceDir) {
61
75
  }
62
76
 
63
77
  async function updateInstructionFiles(projectDir) {
64
- for (const name of ['AGENTS.md', 'CLAUDE.md']) {
78
+ const files = [
79
+ ['AGENTS.md', CODEX_INSTRUCTIONS],
80
+ ['CLAUDE.md', CLAUDE_INSTRUCTIONS],
81
+ ];
82
+ for (const [name, managedBlock] of files) {
65
83
  const file = path.join(projectDir, name);
66
84
  const source = await exists(file) ? await readFile(file, 'utf8') : '';
67
- await writeFile(file, withManagedBlock(source), 'utf8');
85
+ await writeFile(file, withManagedBlock(source, managedBlock), 'utf8');
68
86
  }
69
87
  }
70
88