What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

You can generate Playwright tests with AI in two main ways: record a browser flow with Playwright Codegen, or use Playwright Test Agents to explore an application, plan scenarios, generate test files, and attempt repairs. Codegen is a good fit when you can perform the flow you want to test; agents are better suited to requirement-led work. Neither route decides whether a test captures the right product behavior. Review the scenarios and assertions, then run the tests and investigate the results.

Choose how you want AI to generate the test

Start with the input you have. If you can demonstrate a known flow in a browser, record it with Codegen. If you have a requirement—such as a guest checkout scenario—and want an agent to explore the application and draft a suite, use Playwright Test Agents.

Route What you provide What you get Best fit
Playwright Codegen Browser actions you perform, optionally with recording settings A test-code draft, with supported assertions such as visibility, text, and value A concrete flow you can reproduce in the browser
Playwright Test Agents A focused scenario request, application context, and optionally a seed test or PRD A Markdown plan followed by generated Playwright Test files; a healer can attempt repairs Requirement-led exploration and generation across a flow

Both approaches need human review. Codegen can ground a draft in actions you perform, but does not decide which scenarios matter or infer the full product specification. Agents can structure more of the workflow, but their output still needs to be checked against what the product is meant to do. The official documentation does not establish comparative success rates or a universally better route.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prepare the project before generating tests

  1. Install Playwright and establish a baseline. Follow the current Playwright installation guide for your project, then run its starter tests. Confirm the application starts and that the test environment and required data are usable before asking a generator to build on them.
  2. Keep the installed version in view. Agent definitions and tool instructions can change. When you update Playwright, regenerate agent definitions using the setup command appropriate to your client.
  3. Identify the behavior to verify. Write down the user action and the expected result. “Test checkout” is too broad; “as a guest, submit valid shipping details and reach the order-review screen” gives a planner or a person recording a flow something concrete to validate.
  4. Make setup repeatable. Identify the account, data, fixtures, dependencies, and hooks the test needs. If an agent should reuse the project’s initialization, provide a seed test that establishes it.

A working baseline helps distinguish generated-test problems from an application or environment that was already failing.

Option 1: record a flow with Playwright Codegen

Codegen opens a browser for you to use and generates test code from your interactions. It prioritizes role, text, and test-id locators, and attempts to make a locator unique if it finds multiple matches. It can generate visibility, text, and value assertions. Treat its output as a draft: a recorded click is not by itself proof that the expected business outcome occurred.

Generate and refine a draft

  1. Start recording: run npx playwright codegen https://your-app.example, replacing the example with your application URL.
  2. Perform the smallest useful flow. Use the same starting conditions the test should have. For example, navigate to the relevant page, enter valid form data, submit, and reach the outcome you intend to verify.
  3. Add assertions for meaningful outcomes. Where the expected result is visible, verify it—for example, a confirmation heading or a resulting status—not merely that the submit control was clicked. Assertions should reflect the requirement, not whatever text happened to be easiest to record.
  4. Copy the draft into the test suite. Edit the generated code to fit the project’s fixtures, test data, and conventions. Remove incidental steps that do not contribute to the scenario.
  5. Run the test and review it. Confirm that the assertion fails when the expected result is absent and passes when the intended behavior occurs.

The VS Code extension also supports recording from the Testing sidebar. Codegen can be configured for a device, viewport, locale, timezone, geolocation, color scheme, and authenticated storage. Choose settings that match the scenario rather than assuming a default browser context represents every user.

Authentication storage state can contain sensitive information. Keep saved storage state local and out of source control; do not treat it as harmless fixture data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Option 2: use Playwright Test Agents

Playwright documents a three-agent workflow. The Planner explores the application and writes a Markdown plan; the Generator transforms a plan into Playwright Test files and verifies selectors and assertions while performing scenarios; the Healer runs a failing test, replays its steps, inspects the UI, suggests a patch, and reruns until it passes or a guardrail stops the loop. The documentation notes that a healer may produce a passing test or a skipped test if it believes the functionality is broken. A passing repair is not proof that the original behavior was correct, and a skipped test still needs investigation.

Initialize agents

For the documented VS Code setup, run:

npx playwright init-agents --loop=vscode

Documented client choices also include Claude Code, Codex, and OpenCode. Use the option that matches your agent client and consult the current Playwright guide for the right setup and compatibility details. The documentation says VS Code v1.105, released October 9, 2025, is needed for the agentic experience to function properly in VS Code; compatibility requirements can change.

When Playwright is updated, regenerate the definitions so the agent instructions stay aligned with the installed version.

Give the Planner useful context

Ask for one focused flow and name its intended outcomes. A seed test can perform project initialization and provide global setup, dependencies, fixtures, and hooks. A Product Requirements Document can add further context. For example, request a plan for guest checkout, specify which outcome should appear after valid submission, and state any important boundary conditions the scenario must cover.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Review the Markdown plan before generation. Check that it describes the right starting state, actions, and expected results. If the plan omits a business rule or assumes data that cannot be reproduced, correct the plan or its context rather than asking the Generator to turn a weak plan into more code.

Review generated files and healer changes

Inspect each generated scenario for meaningful assertions, appropriate locators, repeatable data, and isolation from other tests. When the Healer suggests a patch, compare it with the intended requirement and the failure evidence. A patch that makes a test green by weakening an assertion, skipping a meaningful case, or changing the scenario is not a valid repair unless that change is justified by the product behavior.

Use MCP or CLI when an agent needs to explore the browser

Playwright MCP lets an AI assistant interact with a page using structured accessibility snapshots containing roles and text. Its documented examples include navigation, form entry, clicks, and screenshots. Playwright CLI is another option for coding-agent browser control.

These are workflow choices, not interchangeable guarantees. Playwright describes CLI as suitable for agents that favor token-efficient, skill-based browser control; MCP suits specialized loops that benefit from persistent state and iterative reasoning over page structure. Choose based on how the agent is expected to work, not a claim that one is universally better.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Security warning: Playwright’s MCP documentation labels browser_run_code_unsafe as RCE-equivalent because it executes arbitrary JavaScript in the Playwright server process. Enable it only for trusted MCP clients. Do not present arbitrary-code execution as a harmless default for an agent setup.

Run the generated tests and decide what failures mean

Run the suite or a focused file in the configured project. Playwright tests run headlessly and in parallel by default, subject to project configuration. A green run establishes that the test executed successfully under that setup; it does not establish that the suite covers every important scenario or that the expected result is the right one.

Use the HTML report to filter and inspect results. UI Mode and the Playwright Inspector can expose test steps, logs, errors, network activity, DOM snapshots, and locator tools. These help you determine whether a failure comes from the test, its setup, the environment, or the application.

Debug in a useful order

  1. Check the locator. Did it target the intended control, and is it still unique? Review the DOM snapshot and locator tools rather than immediately adding a wait.
  2. Check setup and data. Confirm the application state, account, fixtures, dependencies, and hooks match the test’s assumptions. Make test data reproducible and keep independent tests isolated enough for the run you intend.
  3. Check timing and environment. Inspect the steps, logs, and network activity. Determine whether the application had time to reach the expected state or whether the failure is tied to a particular environment or configuration.
  4. Check the product behavior. If setup and test mechanics are sound, compare the observed behavior with the requirement. A real defect should not be “fixed” by weakening the assertion.
  5. Review repairs and rerun. Treat a healer patch as a proposal. Confirm that it preserves the expected behavior and rerun the relevant tests after changes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Screenshot evidence is separate from test generation

A screenshot can help document a rendered state, but capturing an image is not the same as generating a Playwright test: it does not define assertions, scenario coverage, or expected behavior. If you need a screenshot alongside a test workflow, ScreenshotNeo is a separate website screenshot API and MCP server for developers. Its capture options include full-page screenshots with lazy images loaded and selecting an element by CSS selector.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

For a clean website screenshot without setting up a browser capture script, make one GET request. Replace the target URL as needed. See the ScreenshotNeo API documentation for options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month—no card required.

Common problems and fixes

  • The generated test clicks the right control but proves nothing. Add an assertion for the outcome required by the scenario, such as the resulting confirmation or state. Review whether that assertion would catch the failure the test is meant to detect.
  • A locator matches the wrong item or multiple items. Inspect the live page and DOM snapshot, then choose a locator tied to the intended role, text, or test ID. Re-run the scenario to verify it targets the correct control.
  • An agent plan omits setup or assumes unavailable data. Supply a seed test for initialization, fixtures, dependencies, and hooks; provide the relevant product context and correct the plan before generation.
  • A test passes locally but fails in the suite. Look for shared state, non-repeatable data, or configuration differences. Run the focused test and broader suite, and inspect reports and logs rather than assuming the generated test is reliable in every run context.
  • A healer makes a test pass by skipping it or changing its intent. Review the proposed patch against the requirement. A skipped case or weakened assertion needs an explicit decision, not automatic acceptance.
  • MCP setup enables arbitrary code execution. Treat browser_run_code_unsafe as RCE-equivalent and enable it only for trusted MCP clients.
  • Saved login state risks leaking credentials. Keep authentication storage local and out of source control.

Frequently Asked Questions

Can Playwright generate tests automatically?

Yes. Codegen records actions into a test draft, while Playwright Test Agents can plan scenarios, generate test files, and attempt repairs. Review and run the result before relying on it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do I need an AI coding assistant to use Codegen?

No. Codegen records browser interactions directly. Playwright Test Agents and the MCP or CLI routes are the agent-oriented choices.

Does a passing generated test prove the feature is correct?

No. It proves the test passed under its setup. You still need to check that the scenario and assertions represent the intended requirement.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.