Metadata-Version: 2.4
Name: robotframework-browser-recorder
Version: 0.4.0
Summary: Record browser interactions and generate Robot Framework tests using Browser library
Author: Robot Framework Browser Recorder Contributors
License: Apache-2.0
Project-URL: Homepage, https://github.com/yourusername/robotframework-browser-recorder
Project-URL: Documentation, https://github.com/yourusername/robotframework-browser-recorder#readme
Project-URL: Repository, https://github.com/yourusername/robotframework-browser-recorder
Project-URL: Issues, https://github.com/yourusername/robotframework-browser-recorder/issues
Keywords: robotframework,browser,playwright,testing,automation,recorder
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Testing
Classifier: Framework :: Robot Framework
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: playwright>=1.40.0
Requires-Dist: robotframework>=6.0
Requires-Dist: robotframework-browser>=17.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: flake8>=6.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Dynamic: license-file

# Robot Framework Browser Recorder

A Python package that records browser interactions using Playwright's codegen feature and automatically converts them to Robot Framework test cases using the [Browser library](https://marketsquare.github.io/robotframework-browser/Browser.html).

## Features

- 🎥 **Record browser interactions** using Playwright's powerful codegen tool
- 🤖 **Automatic conversion** to Robot Framework test syntax
- 🌐 **Multi-browser support**: Chromium, Firefox, and WebKit
- 🎯 **Simple CLI** for quick test generation
- 📝 **Clean, readable output** with simplified selectors (e.g., `data-test=login` instead of `[data-test="login"]`)

## Installation

### Prerequisites

- Python 3.8 or higher
- Playwright (installed automatically with the package)

### Install the package

```bash
pip install robotframework-browser-recorder
```

### Install Playwright browsers

After installing the package, you need to install Playwright browsers:

```bash
playwright install  # Install all browsers
# OR install specific browsers:
playwright install chromium
playwright install firefox
playwright install webkit
```

### Install Robot Framework Browser library

```bash
pip install robotframework-browser
rfbrowser init
```

## Quick Start

### Basic Recording

Record browser interactions and generate a Robot Framework test:

```bash
rfbrowser-record --url https://example.com
```

This will:
1. Open a browser window with the Playwright inspector (Chromium by default)
2. Navigate to the specified URL
3. Record all your interactions (clicks, typing, etc.)
4. Generate a `recorded_test.robot` file when you close the browser

### Run Your Test

After recording, run your test with:

```bash
robot recorded_test.robot
```

## Usage

### Command Line Interface

```bash
rfbrowser-record [OPTIONS]
```

#### Options

| Option | Short | Description | Default |
|--------|-------|-------------|---------|
| `--url` | `-u` | Initial URL to navigate to | None |
| `--browser` | `-b` | Browser to use (chromium, firefox, webkit) | chromium |
| `--output` | `-o` | Output file path | recorded_test.robot |
| `--test-name` | `-n` | Name of the test case | Recorded Test |
| `--version` | | Show version | |

### Examples

#### Record with Firefox

```bash
rfbrowser-record --browser firefox --url https://example.com
```

#### Record with custom output file

```bash
rfbrowser-record --url https://example.com --output my_test.robot
```

## Supported Actions

The converter supports the following Playwright actions:

### Interactions

| Playwright Action | Robot Framework Keyword |
|-------------------|-------------------------|
| `page.goto(url)` | `New Page    url` |
| `page.click(selector)` or `.click()` | `Click    selector` |
| `page.fill(selector, value)` or `.fill(value)` | `Type Text    selector    value` |
| `page.press(selector, key)` | `Keyboard Key    press    key` |
| `page.check(selector)` or `.check()` | `Check Checkbox    selector` |
| `page.uncheck(selector)` or `.uncheck()` | `Uncheck Checkbox    selector` |
| `page.select_option(selector, value)` or `.select_option(value)` | `Select Options By    selector    value    value` |
| `page.set_input_files(selector, file)` or `.set_input_files(file)` | `Upload File By Selector    selector    file` |
| `page.hover(selector)` or `.hover()` | `Hover    selector` |
| `page.dblclick(selector)` or `.dblclick()` | `Click    selector    clickCount=2` |
| `page.screenshot(path=path)` | `Take Screenshot    path` |
| `page.wait_for_load_state(state)` | `Wait For Load State    state` |

### Assertions / Verifications

| Playwright Assertion | Robot Framework Keyword |
|---------------------|-------------------------|
| `expect(locator).to_be_visible()` | `Get Element States    selector    validate    visible` |
| `expect(locator).to_have_text(text)` | `Get Text    selector    ==    text` |
| `expect(locator).to_contain_text(text)` | `Get Text    selector    ==    text` |
| `expect(locator).to_have_value(value)` | `Get Property    selector    value    ==    value` |
| `expect(locator).to_be_checked()` | `Get Checkbox State    selector    ==    checked` |
| `expect(page).to_have_url(url)` | `Get Url    ==    url` |
| `expect(page).to_have_title(title)` | `Get Title    ==    title` |

## Example Output

After recording interactions on a website, you'll get a clean Robot Framework test:

```robot
*** Settings ***
Library    Browser


*** Test Cases ***
Login Test
    New Browser    chromium    headless=False
    New Context    viewport={'width': 1920, 'height': 1080}
    New Page    https://example.com
    Click    data-test=nav-sign-in
    Type Text    data-test=email    test@test.nl
    Type Text    data-test=password    SuperSecretPassword!
    Click    data-test=login-submit
```

Notice how selectors are simplified:
- `[data-test="nav-sign-in"]` becomes `data-test=nav-sign-in`
- `[id="submit"]` becomes `id=submit`

## Development

### Setup Development Environment

```bash
# Clone the repository
git clone https://github.com/yourusername/robotframework-browser-recorder.git
cd robotframework-browser-recorder

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

# Install Playwright
playwright install chromium
```

### Running Tests

```bash
pytest tests/
```

### Code Formatting

```bash
black robotframework_browser_recorder/
```

## Troubleshooting

### Playwright not found

If you get an error about Playwright not being installed:

```bash
pip install playwright
playwright install chromium
```

### Browser library not found

Make sure the Robot Framework Browser library is installed:

```bash
pip install robotframework-browser
rfbrowser init chromium
```

### Recording produces no output

Make sure you actually perform some interactions in the browser before closing it. The recorder only captures actions like clicks, typing, navigation, etc.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

Apache License 2.0

## Related Projects

- [Robot Framework](https://robotframework.org/)
- [Robot Framework Browser Library](https://github.com/MarketSquare/robotframework-browser)
- [Playwright](https://playwright.dev/)

## Acknowledgments

This project builds upon the excellent work of:
- The Robot Framework community
- The Playwright team at Microsoft
- The Browser library maintainers
