Metadata-Version: 2.5
Name: agent2playwright
Version: 0.1.0
Summary: Convert browser-agent trajectories (browser-use, Playwright MCP) into certified deterministic pytest-Playwright tests.
Project-URL: Homepage, https://github.com/prakash888kp/agent2playwright
Project-URL: Documentation, https://github.com/prakash888kp/agent2playwright#readme
Project-URL: Issues, https://github.com/prakash888kp/agent2playwright/issues
Project-URL: Source, https://github.com/prakash888kp/agent2playwright
Author: agent2playwright Contributors
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agent history,agent to playwright,agent trajectory,agent2playwright,browser-use,ci test compiler,deterministic browser tests,e2e test generation,otir,playwright,playwright mcp,pytest,pytest-playwright,workflow-use
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Requires-Dist: pydantic>=2.7
Requires-Dist: rich>=13.7
Requires-Dist: typer>=0.12
Provides-Extra: dev
Requires-Dist: pytest-playwright>=0.5; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# agent2playwright

**Convert browser-agent trajectories into certified deterministic pytest-Playwright tests.**

`agent2playwright` (CLI: `a2pw`) compiles noisy browser-agent runs — browser-use, Playwright MCP, workflow-use style histories — into CI-ready pytest-Playwright suites using multi-run consensus, Playwright locator policy, secret sanitization, and a certification scorecard. No LLM is required at replay time.

```text
browser-use / MCP / OTIR runs
            │
            ▼
     adapt → OTIR (open IR)
            │
            ▼
 clean → consensus → harden → sanitize → assert
            │
            ▼
  pytest-playwright + POM + SCORECARD.md
```

## Install

```bash
pip install agent2playwright
# or from source:
pip install -e ".[dev]"
python -m playwright install chromium
```

## Quickstart

```bash
# Compile 3 agent runs of the same task into one certified test
a2pw compile \
  examples/trajectories/login_run_a.json \
  examples/trajectories/login_run_b.json \
  examples/trajectories/login_run_c.json \
  -o a2pw-out \
  --test-name test_login_dashboard
```

```python
from agent2playwright import compile_trajectories
from agent2playwright.adapters import detect_and_load
from agent2playwright.models import CompileOptions

runs = [detect_and_load(p) for p in [
    "examples/trajectories/login_run_a.json",
    "examples/trajectories/login_run_b.json",
    "examples/trajectories/login_run_c.json",
]]
result = compile_trajectories(runs, CompileOptions(test_name="test_login_dashboard"))
print(result.scorecard.summary)
Path("test_login_dashboard.py").write_text(result.test_code)
```

## Why agent2playwright?

| Capability | Raw agent dump | agent2playwright |
| --- | --- | --- |
| Multi-run consensus (drop exploration noise) | No | **Yes** |
| CI certification scorecard | No | **Yes** |
| Playwright locator policy (role/label/test id) | Rare | **Enforced** |
| Intent → web-first assertions | Rare | **Yes** |
| Secret → `A2PW_PASSWORD` env vars | Sometimes | **Always** |
| pytest-Playwright + Page Object Model | Rare | **Default** |

## Live verification

```bash
python benchmarks/live_multisite.py
```

| Site | Live | Score |
| --- | --- | --- |
| SauceDemo login | 3/3 | 98.7 |
| SauceDemo checkout | 3/3 | 89.7 |
| the-internet login | 3/3 | 98.7 |
| the-internet dropdown | 3/3 | 85.0 |
| the-internet dynamic loading | 3/3 | 98.7 |
| Playwright TodoMVC | 3/3 | 98.7 |

## How do I convert browser-use agent history to Playwright pytest?

1. Save agent history JSON from browser-use (or export OTIR).
2. Run the same task 2–3 times for consensus.
3. Compile:

```bash
a2pw compile run_a.json run_b.json run_c.json -o tests_out --test-name test_flow
export A2PW_PASSWORD='...'
pytest tests_out/tests --browser chromium
```

## How is agent2playwright different from browse-to-test / recast / flow2skill?

| Tool | Focus |
| --- | --- |
| **agent2playwright** | Agent trajectories → **certified pytest-Playwright** via consensus + scorecard |
| browse-to-test | Recording/automation data → scripts (broader converter) |
| recast | Agent recordings → static Playwright (often TS-first) |
| flow2skill | Human Playwright codegen → skill + pytest proof |

Use agent2playwright when you already have **browser-agent runs** and need **CI-stable pytest** with a fail/pass certification gate.

## Can I compile multiple agent trajectories into one stable test?

Yes. Pass multiple JSON files to `a2pw compile`. Steps must agree across enough runs (default 67%) to survive consensus. Retries, wrong clicks, and one-off detours are dropped.

## OTIR

Open Trajectory Intermediate Representation — driver-agnostic JSON (`src/agent2playwright/schema/otir.schema.json`).

```bash
a2pw adapt raw-browser-use.json -o otir.json
a2pw certify otir.json
```

## CLI

```bash
a2pw adapt <trajectory.json> -o otir.json
a2pw compile <run1.json> [run2.json ...] -o out/ --require-cert
a2pw certify <trajectory.json>
```

Exit codes: `0` certified, `1` compiled but not certified, `2` hard failure with `--require-cert`.

## License

Apache-2.0
