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

You can use Playwright Test Agents in a Python project, but the documented agents are not a Python test generator: their examples create Playwright Test files in TypeScript. For Python-native end-to-end tests, Playwright recommends its pytest plugin. Use the agents for planning, generating and healing in a supported agent loop, then review the output before deciding whether it belongs in your Python suite. For recorded Python code, use Python Codegen instead.

What Playwright Test Agents do—and what they do not document for Python

Playwright describes three agents that can be run independently, in sequence, or as a loop:

  • Planner: explores an application and writes a Markdown plan of scenarios or user flows.
  • Generator: reads the plan and creates executable Playwright Test files, checking selectors and assertions as it works.
  • Healer: investigates a failing test, replays actions, looks for equivalent UI elements or flows, suggests a repair and reruns the test within guardrails.

The official Test Agents documentation illustrates generated Playwright Test files with TypeScript. The reviewed documentation does not establish that these agents generate Python pytest tests. That is a documentation boundary, not proof that Python output is impossible. Check the language and project structure of any generated files rather than assuming they can be dropped into a pytest suite. Playwright Test Agents documentation

The distinction matters because Python’s recommended route is different: the official Playwright Python guide recommends the pytest plugin for end-to-end testing. Python Codegen can record a browser interaction and emit Python code, but it is not the planner-generator-healer agent workflow. Playwright for Python · Playwright supported languages · Python Codegen

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

Initialize Test Agents in a supported agent loop

Playwright’s documented setup command initializes agent definitions for a chosen client loop. The examples include Codex, VS Code, Claude and OpenCode. This creates the agent instructions and files for that workflow; it does not, by itself, convert a Python project into a pytest-based Test Agents generator.

  1. Update Playwright first. Use the version already appropriate for your project, then initialize agents. Regenerate the definitions when you update Playwright so they can reflect the current tools and instructions.
  2. Run the initialization command from the project directory:
    npx playwright init-agents --loop=codex

    Replace codex with vscode, claude or opencode as appropriate to your agent client.

  3. Open the project in the selected client and use the generated agent definitions according to that client’s workflow. VS Code’s agentic experience requires VS Code v1.105, released October 9, 2025, according to the Playwright agent documentation.

Use the current agent documentation for setup details that may change between Playwright versions. The Test Agents feature was introduced in Playwright 1.56, per the Playwright release notes.

Run the planner, generator and healer with a Python project

1. Prepare a seed test and a precise scenario

Give the planner a clear request describing the user flow you want covered. Provide a seed test that performs the project’s required initialization; a product requirements document is optional. Playwright says the planner runs the seed test so global setup, project dependencies, fixtures and hooks can be applied. A useful request names the starting state, actions, expected outcomes and relevant edge cases instead of asking vaguely for “tests for the app.”

For example, ask for a plan covering a signed-in user who adds an in-stock item to a cart, verifies the cart count and total, and handles an unavailable item. Keep credentials and environment-specific setup in your project’s normal secure configuration rather than embedding secrets in a prompt or generated test.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

2. Review the Markdown plan

Inspect the planner’s output before generation. Confirm it reflects real product behavior, includes meaningful assertions, and does not assume data or accounts your test environment lacks. The plan is the right place to correct scope and missing scenarios; generating first and trying to repair a misunderstood requirement later creates avoidable churn.

3. Generate, then inspect the language and structure

Ask the generator to turn the accepted plan into tests. The documented generator verifies selectors and assertions as it performs scenarios, but Playwright notes that generated tests can initially have errors for the healer to address. Inspect the resulting files: if they are TypeScript Playwright Test files, they are not pytest tests simply because the surrounding application is written in Python.

4. Use the healer as a repair proposal, not an authority

The healer runs a failing test, replays its steps, examines the UI for equivalent elements or flows and may propose a locator or wait change. It can rerun until the test passes or a guardrail stops the loop. The documented outcome can also be a skipped test if the healer believes the functionality is broken. Review any patch: a passing test after a change does not prove that the repaired assertion still checks the intended behavior.

For Python teams, keep approved tests in the pytest workflow described below. If you evaluate Test Agents, treat their output as a separate generated artifact unless and until your team confirms its language and integration fit.

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

Set up Python end-to-end tests with pytest-playwright

For a Python-native suite, the official installation and run sequence is:

pip install pytest-playwright
playwright install
pytest

Run these commands in the intended Python environment. The plugin provides a page fixture and supports context isolation and multiple browser configurations. Playwright’s Python library supports synchronous and asynchronous APIs; the pytest examples use pytest discovery conventions, including test files and functions named with test_, and Playwright’s expect assertions. See the Python introduction for current installation requirements; its published guide lists Python 3.8+ and supported operating systems and distributions, which should be checked again when creating a fresh environment.

A small pytest example

This illustrates the shape of a Python test using the plugin’s fixture and an assertion. Replace the URL and expected page text with values from your application.

from playwright.sync_api import Page, expect


def test_homepage_has_expected_heading(page: Page) -> None:
    page.goto("https://example.com")
    expect(page.get_by_role("heading", name="Example Domain")).to_be_visible()

Save it as a discoverable test file such as test_homepage.py, then run pytest. For an async project, use the async API and the setup pattern documented in the Python guide rather than mixing sync and async calls in the same test.

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

Record Python interactions with Codegen

If the main goal is to bootstrap Python code from a browser interaction, use Codegen rather than treating Test Agents as a Python generator. The command reference shows this CLI pattern:

playwright codegen --target=python https://example.com

Interact with the opened browser to record a flow, then review and adapt the emitted code. Recording is a starting point, not a substitute for choosing stable locators, adding assertions that verify the intended behavior, and arranging data/setup so the test is repeatable. The Python guide also describes interactive recording and sync/async custom setup examples. See Python Codegen documentation.

Choose the route that matches the output you need

Route Best suited to Output and runner Key caveat
Playwright Test Agents Agent-guided exploration, planning, generation and healing Markdown plan and documented Playwright Test files, initialized for a supported agent loop Official examples reviewed show TypeScript tests; Python pytest output is not established in the documentation.
Python pytest + Codegen A Python-native end-to-end suite, with recording to bootstrap a flow where useful pytest-playwright tests; Codegen can emit Python Codegen is not the planner-generator-healer agent chain.

Decide based on the language you need in the repository, the test framework and fixtures you already maintain, whether agent-led exploratory planning is valuable, and how much human review your team wants for generated or repaired tests. For a team committed to Python, pytest-playwright is the documented testing path; use Codegen when recording helps, and evaluate Test Agents separately when their agent workflow is the goal.

Or skip the browser setup

If your immediate need is a screenshot rather than an interactive test suite, ScreenshotNeo takes a website URL through a single API request and returns an image or PDF. It is not a replacement for Playwright Test Agents or pytest: it captures pages rather than generating or running your test suite. Cookie banners are accepted and removed before capture, along with supported newsletter popups and chat widgets. Bot checks, blank pages and failed loads are never billed; responses include verdict and billing headers. An MCP server provides screenshot tools for AI agents, and the free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.

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

One-call cURL example (see the ScreenshotNeo API documentation):

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

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card required.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common issues

The agents are producing TypeScript, not Python

This matches the language shown in the documented Test Agents examples. Do not assume that changing your application language or prompt changes the agents into a pytest generator. Use pytest-playwright for Python tests, or use Codegen’s Python target when recording is the desired workflow.

The initialization command does not work in the selected client

Confirm that the --loop value is one of the documented client values: codex, vscode, claude or opencode. Check the current Playwright agent documentation for version-specific setup, and regenerate definitions after Playwright updates.

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.

The planner misses setup or starts in the wrong state

Provide a seed test that performs the necessary initialization and clarify which user, environment and data state the scenario assumes. The planner runs the seed test for setup such as global setup, dependencies, fixtures and hooks; an unclear request or incomplete setup can still produce an unsuitable plan.

A generated test fails on a selector or wait

First decide whether the failure reveals a real application issue, a test-data problem or a brittle locator/timing assumption. The healer may suggest an alternative locator or wait, but review whether that adjustment preserves the intended assertion before accepting it.

The healer skips a test

A skipped result may mean the healer believes the functionality is broken, rather than that the test has been repaired. Check the product behavior and failure details yourself, then decide whether the test should remain failing, be corrected, or be marked skipped according to your team’s policy.

pytest does not find the Python test

Use pytest’s documented naming conventions: a discoverable file such as test_checkout.py and test functions named with the test_ prefix. Verify that the plugin is installed in the active environment and that the browser installation step has completed.

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

FAQ

Can Playwright Test Agents generate Python tests?

The reviewed official agent documentation demonstrates Playwright Test files with TypeScript examples; it does not establish a Python-native pytest generator. That does not demonstrate Python output is impossible, but it is not a capability to rely on based on those docs.

Can I use Codegen and Test Agents in the same project?

They address different tasks and can be evaluated side by side: Codegen records Python interactions, while Test Agents provide planner, generator and healer roles in a supported agent loop. Review and maintain any output in the framework and language your project actually runs.

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.