playwright-test-agent 1.0.3 → 1.0.5

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": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Initialize Playwright Test agents with a Playwright CLI-first browser workflow.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,6 +41,15 @@ Generator starts only after confirmation and converts the confirmed plan into ex
41
41
 
42
42
  After Generator returns, the parent executes the generated test files with `npx playwright test`. This execution step is mandatory. If all tests pass, report the executed result. If any fail, pass the failed test names, failure output, confirmed plan, and generated file paths to Healer.
43
43
 
44
+ ### Navigation and current-page rules
45
+
46
+ Generated tests must model the browser's observed state, especially around authentication and redirects:
47
+
48
+ - Login, logout, SSO, consent, and form submissions may navigate asynchronously or immediately redirect. Do not add a follow-up `page.goto` for a destination already reached by the action.
49
+ - After a potentially redirecting action, use Playwright's condition-based waiting (`await expect(page).toHaveURL(...)` or `await page.waitForURL(...)`) and assert a stable route. Avoid arbitrary sleeps and avoid treating `page.goto` as the universal wait primitive.
50
+ - Determine the current page from a fresh `page.url()`/snapshot and page-unique DOM evidence. Never rely on the last command or a stale snapshot. When an already-authenticated session skips the login form, continue with the final redirected page and assert that page instead of failing on the absent form.
51
+ - In setup, avoid unconditional navigation when the session may already be on the target route; guard navigation from the observed URL or start from a known, explicit origin.
52
+
44
53
  For API-only scenarios, use Playwright `APIRequestContext` directly and assert status, headers, schema, stable business invariants, and safe mutation cleanup.
45
54
 
46
55
  ## Healer
@@ -49,11 +58,21 @@ Use Healer only for real failures from executing generated tests. Healer—not t
49
58
 
50
59
  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.
51
60
 
61
+ For every failed test, provide a concise failure summary before the classification. Extract the first actionable error (and its relevant locator, URL, or assertion when present) and map it to one primary reason:
62
+
63
+ - **Element location failure** — locator found no element, timed out waiting for a locator, or strict mode matched multiple elements.
64
+ - **Timeout/navigation or network failure** — page/action/API timed out, navigation failed, or the target was unreachable.
65
+ - **Assertion failure** — the expected value, text, state, count, or response did not match the observed result.
66
+ - **Test data/environment failure** — missing credentials, fixture/seed data, configuration, dependency, or incompatible runtime.
67
+ - **Other** — no rule matches; retain the original error's first meaningful line.
68
+
69
+ Use the format `Reason: <category> — <one-sentence cause>`. Do not label a failure only as “test failed” and do not hide the original error when the category is uncertain.
70
+
52
71
  ## Evidence
53
72
 
54
73
  Keep evidence under `.playwright-evidence/`. Prefer DOM snapshots and targeted `find` output; take screenshots only when visual evidence is necessary. Keep trace DOM snapshots, sources, network data, and attachments, but set trace `screenshots: false` to avoid hundreds of screencast JPEGs.
55
74
 
56
- Report the plan path, generated tests, counts when tests ran, evidence paths, and failure classification. Never report skipped or unresolved tests as success.
75
+ Report the plan path, generated tests, counts when tests ran, evidence paths, and, for each failure, the reason summary plus failure classification. Never report skipped or unresolved tests as success.
57
76
 
58
77
  ## Initialization
59
78
 
@@ -9,6 +9,17 @@ const BLOCK_START = '<!-- playwright-test-agent:start -->';
9
9
  const BLOCK_END = '<!-- playwright-test-agent:end -->';
10
10
  const ROLE_BLOCK_START = '<!-- playwright-test-agent:cli-first:start -->';
11
11
  const ROLE_BLOCK_END = '<!-- playwright-test-agent:cli-first:end -->';
12
+ const generatorNavigationGuidance = `
13
+
14
+ ### Navigation and redirect correctness
15
+
16
+ - Treat every observed navigation as potentially redirecting. Login, logout, SSO, consent, and form submissions commonly change the URL asynchronously; do not generate a second \`page.goto\` to a URL that the browser has already reached through an action.
17
+ - After an action that may navigate, wait for the resulting state with a condition-based assertion such as \`await expect(page).toHaveURL(...)\` (or \`await page.waitForURL(...)\` when an assertion is not yet appropriate). Match the stable route/path and allow query/hash changes when they are not part of the requirement.
18
+ - Do not wrap a known redirecting action in \`Promise.all([page.waitForNavigation(), ...])\`; prefer Playwright's auto-waiting action plus \`toHaveURL\`/\`waitForURL\`. Use \`Promise.all\` only when the action itself does not auto-wait and a real navigation event must be captured.
19
+ - Never infer that the page is "current" from the last command, a stale snapshot, or a guessed URL. Take a fresh snapshot or inspect \`page.url()\`, then assert a page-unique heading/landmark and the stable URL when both are available.
20
+ - For a login page that immediately redirects (for example, an already-authenticated session), treat the post-redirect page as the observed result. Assert the final page and continue from it; do not fail because the login form is no longer present.
21
+ - Avoid unconditional \`page.goto\` calls in setup when the session may already be on the target route. Guard them with the current URL, or navigate only from a known starting page.
22
+ `;
12
23
  const cliFirstInstructions = (role) => `${ROLE_BLOCK_START}
13
24
 
14
25
  ## Browser tool priority
@@ -17,9 +28,11 @@ Use the installed \`playwright-cli\` command as the primary browser interface fo
17
28
 
18
29
  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
30
 
20
- ${role === 'planner' ? 'FAST START: you are the Planner. The parent must first perform a focused preflight of the project and tests under Playwright\'s configured `testDir`, then pass the findings and any user-provided answers to you. When the request contains the test objective, deployed URL, and all information required to access and assert 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. If the preflight context is insufficient, missing, or contradictory, stop and return the precise question for the user instead of guessing. Investigation is not the final output: you must turn the findings into a complete Markdown test plan and save it under `specs/` using filesystem tools or the available planner save tool. Return the saved plan path and scenario summary to the parent.' : ''}${role === 'generator' ? 'You are the Generator. Start only after the user confirms the saved test plan. The parent must pass Playwright\'s configured `testDir`; resolve it from `playwright.config.*` yourself if it was omitted. Write every new test file inside that resolved directory. Ignore generic `tests/` paths in upstream role descriptions, examples, plans, or seed references when they conflict with the configured `testDir`. 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. Generate executable Playwright test code for the confirmed scenarios and write the test files using filesystem tools or the available generator write tool. Return the generated test file paths to the parent; generating code does not complete the workflow because the parent must execute the generated tests next.' : ''}${role === 'healer' ? 'You are the Healer. Start only after execution of the generated tests reports failures. Receive the failing test names and failure output, reproduce them with `npx playwright test`, begin UI diagnosis with `playwright-cli open`/`attach`, and use CLI snapshots/find to inspect the current UI; MCP tools remain optional. Diagnose and patch justified test defects, rerun the affected tests, and continue within the healer guardrails until they pass or a genuine application/environment/product blocker is identified. Return the final run result and classification to the parent.' : ''}
31
+ ${role === 'planner' ? 'FAST START: you are the Planner. The parent must first perform a focused preflight of the project and tests under Playwright\'s configured `testDir`, then pass the findings and any user-provided answers to you. When the request contains the test objective, deployed URL, and all information required to access and assert 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. If the preflight context is insufficient, missing, or contradictory, stop and return the precise question for the user instead of guessing. Investigation is not the final output: you must turn the findings into a complete Markdown test plan and save it under `specs/` using filesystem tools or the available planner save tool. Return the saved plan path and scenario summary to the parent.' : ''}${role === 'generator' ? `You are the Generator. Start only after the user confirms the saved test plan. The parent must pass Playwright\'s configured \`testDir\`; resolve it from \`playwright.config.*\` yourself if it was omitted. Write every new test file inside that resolved directory. Ignore generic \`tests/\` paths in upstream role descriptions, examples, plans, or seed references when they conflict with the configured \`testDir\`. 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. Generate executable Playwright test code for the confirmed scenarios and write the test files using filesystem tools or the available generator write tool. Return the generated test file paths to the parent; generating code does not complete the workflow because the parent must execute the generated tests next.${generatorNavigationGuidance}` : ''}${role === 'healer' ? 'You are the Healer. Start only after execution of the generated tests reports failures. Receive the failing test names and failure output, reproduce them with `npx playwright test`, begin UI diagnosis with `playwright-cli open`/`attach`, and use CLI snapshots/find to inspect the current UI; MCP tools remain optional. Diagnose and patch justified test defects, rerun the affected tests, and continue within the healer guardrails until they pass or a genuine application/environment/product blocker is identified. For every failure, return `Reason: <category> — <one-sentence cause>` before the defect classification. Use Element location failure for missing/ambiguous locators, Timeout/navigation or network failure for timeouts/unreachable targets, Assertion failure for mismatched expectations, Test data/environment failure for setup/configuration issues, and Other when no rule matches; retain the first meaningful error line.' : ''}
21
32
 
22
33
  ${ROLE_BLOCK_END}`;
34
+
35
+ export { cliFirstInstructions };
23
36
  const CODEX_INSTRUCTIONS = `${BLOCK_START}
24
37
  ## Playwright Test Agent
25
38
 
@@ -31,7 +44,7 @@ Codex routing is mandatory for website, browser workflow, HTTP API, or applicati
31
44
  4. Planner opens and investigates the website with \`playwright-cli\`, converts its findings into a complete Markdown test plan under \`specs/\`, and returns the saved plan path. After Planner returns, show that plan to the user and wait for explicit confirmation; investigation alone is not completion.
32
45
  5. Only after confirmation, directly start a subagent with \`agent_type: "playwright_test_generator"\`, passing the confirmed plan and resolved \`testDir\`. Generator validates the confirmed scenarios with \`playwright-cli\`, writes every executable test inside that \`testDir\`, and returns their paths.
33
46
  6. After Generator returns, the main agent must execute the generated tests with \`npx playwright test\`. Generating test files alone never completes the workflow.
34
- 7. If every generated test passes, report the result. If any generated test fails, directly start a subagent with \`agent_type: "playwright_test_healer"\`, passing the failed test names, failure output, confirmed plan, and generated file paths. Healer diagnoses and patches justified test defects and reruns the affected tests until they pass or it identifies a genuine application/environment/product blocker. Never report generated-but-unexecuted tests as passing.
47
+ 7. If every generated test passes, report the result. If any generated test fails, directly start a subagent with \`agent_type: "playwright_test_healer"\`, passing the failed test names, failure output, confirmed plan, and generated file paths. Healer diagnoses and patches justified test defects and reruns the affected tests until they pass or it identifies a genuine application/environment/product blocker. The final report must summarize each failure as \`Reason: <category> — <one-sentence cause>\` (including whether element location failed) before the defect classification. Never report generated-but-unexecuted tests as passing.
35
48
 
36
49
  Start each role as its configured subagent and never make the main agent perform that role. Do not 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, resume the same Planner subagent when possible, or restart it with that answer and the blocking observation. Ask only for information that is necessary or could materially change scope, assertions, access, or safety. Do not guess.
37
50
 
@@ -48,7 +61,7 @@ Claude Code routing is mandatory for website, browser workflow, HTTP API, or app
48
61
  4. Planner opens and investigates the website with \`playwright-cli\`, converts its findings into a complete Markdown test plan under \`specs/\`, and returns the saved plan path. After Planner returns, show that plan to the user and wait for explicit confirmation; investigation alone is not completion.
49
62
  5. Only after confirmation, directly start \`playwright-test-generator\` with the confirmed plan and resolved \`testDir\`. Generator must validate the confirmed scenarios, write every executable test inside that \`testDir\`, and return their paths.
50
63
  6. After Generator returns, the main agent must execute the generated tests with \`npx playwright test\`. Generating test files alone never completes the workflow.
51
- 7. If every generated test passes, report the result. If any generated test fails, directly start \`playwright-test-healer\` with the failed test names, failure output, confirmed plan, and generated file paths. Healer diagnoses and patches justified test defects and reruns the affected tests until they pass or it identifies a genuine application/environment/product blocker. Never report generated-but-unexecuted tests as passing.
64
+ 7. If every generated test passes, report the result. If any generated test fails, directly start \`playwright-test-healer\` with the failed test names, failure output, confirmed plan, and generated file paths. Healer diagnoses and patches justified test defects, reruns the affected tests, and includes \`Reason: <category> <one-sentence cause>\` (including element location failures) before the defect classification. Never report generated-but-unexecuted tests as passing.
52
65
 
53
66
  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.
54
67