Metadata-Version: 2.4
Name: playwright-interpreter
Version: 0.1.0
Summary: Interactive REPL for Playwright browser automation with automatic script generation
Project-URL: Homepage, https://github.com/s-sriharsha/playwright-interpreter
Project-URL: Repository, https://github.com/s-sriharsha/playwright-interpreter
Project-URL: Issues, https://github.com/s-sriharsha/playwright-interpreter/issues
Author-email: Sri Harsha Saragadam <sriharshasaragadam@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: automation,browser,playwright,repl,testing
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Requires-Dist: playwright>=1.40.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: rich>=13.0.0
Requires-Dist: typer>=0.9.0
Provides-Extra: dev
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Description-Content-Type: text/markdown

# Playwright Interpreter

Interactive REPL for [Playwright](https://playwright.dev/) browser automation with automatic Python script generation.

Record commands as you explore a site, then export a standalone Playwright script you can run, share, or check into version control.

## Installation

```bash
pip install playwright-interpreter
playwright install
```

For development:

```bash
git clone https://github.com/playwright-interpreter/playwright-interpreter.git
cd playwright-interpreter
pip install -e ".[dev]"
playwright install
```

## Quick Start

Launch the interactive REPL:

```bash
playwright-interpreter
```

Example session:

```text
Playwright Interpreter v0.1.0

pi> launch
pi> goto https://google.com
pi> fill textarea "playwright interpreter"
pi> click input[type=submit]
pi> screenshot result.png
pi> code
pi> exit
```

The `code` command displays the generated script:

```python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)

    page = browser.new_page()

    page.goto("https://google.com")
    page.fill("textarea", "playwright interpreter")
    page.click("input[type=submit]")
    page.screenshot(path="result.png")

    browser.close()
```

On exit, the session is saved automatically:

- `session.json` — recorded commands
- `generated_script.py` — executable Playwright script

## REPL Usage

### Meta Commands

| Command | Description |
|---------|-------------|
| `help` | Show all available commands |
| `history` | Show executed commands |
| `code` | Display generated Python script |
| `save` | Save `session.json` and `generated_script.py` |
| `clear` | Clear recorded actions |
| `export <file>` | Export script to a custom filename |
| `load <session.json>` | Load a previous session |
| `exit` | Exit, save session, and close browser |

### Playwright Commands

| Command | Description |
|---------|-------------|
| `launch` | Launch Chromium browser (opens a new page) |
| `new_page` | Open a new browser page |
| `goto <url>` | Navigate to a URL |
| `click <selector>` | Click an element |
| `dblclick <selector>` | Double-click an element |
| `hover <selector>` | Hover over an element |
| `fill <selector> <text>` | Fill an input field |
| `type <selector> <text>` | Type text into an element |
| `press <selector> <key>` | Press a key on an element |
| `wait <milliseconds>` | Wait for a duration |
| `reload` | Reload the current page |
| `back` | Navigate back |
| `forward` | Navigate forward |
| `screenshot <file>` | Save a screenshot |
| `close` | Close the browser |

Quoted strings are supported for selectors and text with spaces:

```text
pi> fill "#search" "playwright interpreter"
```

## CLI Commands

### Interactive REPL

```bash
playwright-interpreter
```

### Replay a Session

Re-execute recorded actions from a saved session:

```bash
playwright-interpreter replay session.json
```

### Generate Script

Create a Playwright script from a session file without opening a browser:

```bash
playwright-interpreter generate session.json
playwright-interpreter generate session.json -o my_script.py
```

## Examples

### Save During a Session

```text
pi> launch
pi> goto https://example.com
pi> screenshot home.png
pi> save
```

### Load a Previous Session

```text
pi> load session.json
pi> code
```

### Export to Custom File

```text
pi> export my_automation.py
```

## Development

Run tests with coverage:

```bash
pytest
```

Run tests without coverage threshold:

```bash
pytest --no-cov
```

Project structure:

```text
playwright_interpreter/
├── cli.py          # Typer CLI entrypoint
├── repl.py         # Interactive REPL
├── parser.py       # shlex-based command parser
├── commands.py     # Command definitions
├── executor.py     # Playwright command execution
├── session.py      # Browser session management
├── recorder.py     # Action recording and persistence
├── generator.py    # Python script generation
├── models.py       # Pydantic data models
├── exceptions.py   # Custom exceptions
└── utils.py        # Shared utilities
```

## Publishing

Build and publish to PyPI:

```bash
pip install build twine
python -m build
twine upload dist/*
```

Ensure Playwright browsers are installed on target machines:

```bash
playwright install
```

## License

MIT License — see [LICENSE](LICENSE) for details.
