Metadata-Version: 2.4
Name: rf-browser-recorder-toolbar
Version: 0.1.0
Summary: Record Robot Framework browser tests with annotated steps
License-Expression: Apache-2.0
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: robotframework-browser==21.1.0
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Dynamic: license-file

# rf-browser-recorder-toolbar

A browser recorder toolbar that captures actions with
[Robot Framework Browser](https://robotframework-browser.org/) and saves them
as a [Robot Framework](https://robotframework.org/) test. Add **steps** and
**comments** while recording to include them in the generated `.robot` file.

## Prerequisites

- Python 3.12 or newer.
- Node.js, required to initialize Robot Framework Browser.
- A graphical desktop and a trusted application to record.

The recorder uses Browser's private recorder APIs and is pinned to
`robotframework-browser==21.1.0`. Browser and Playwright upgrades require
compatibility testing.

## Install

After publication to PyPI, install the package in your Python environment:

```powershell
pip install rf-browser-recorder-toolbar
rfbrowser init chromium
```

For example, to create and activate a Python 3.12 virtual environment first:

```powershell
py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1
```

## Record a test

With the environment activated, start a recording:

```powershell
rf-browser-recorder-toolbar --url "https://example.com" --name "Example test"
```

1. Perform actions in the browser.
2. Before a logical step, enter its label in the toolbar and select **Add Step**
   (or press Enter).
3. Enter a comment and select **Add Comment** (or press Enter).
4. Wait for the annotation to be confirmed before continuing. Do not interact
   with other tabs while adding it.
5. Stop the recording using Browser's toolbar to save the suite.

The output file must not already exist. Recording is kept in memory until a
clean stop; closing or killing the process early can lose it. Review the
generated test, including annotation placement, before use.

Use only trusted applications: page scripts can read recorder state and send
recorder commands. Values typed in the browser, including passwords, can be
recorded in plain text. Pause recording when entering secrets and review the
output before sharing it.

## Output

| File | Contents |
| --- | --- |
| `tests\robot\<name>.robot` | A new test with Browser actions, steps and comments |

Spaces in the filename become dashes; the Robot test name is unchanged. For
example, `Example test` writes `tests\robot\Example-test.robot`.

The generated suite imports the bundled `Step` library:

```robotframework
*** Settings ***
Library    Browser
Library    rf_browser_recorder_toolbar.steps

*** Test Cases ***
Example test
    [Tags]    browser    recorded
    New Browser    chromium    headless=False
    New Page    https://example.com
    Step    Sign in
    # Check the login page
    Click    text=Sign in
```

`Step` logs its label in the Robot Framework log and console. Install this
package in the environment used to run the generated test. Older recordings
using `rf_browser_toolbar.steps` must be updated to
`rf_browser_recorder_toolbar.steps`.

The generated test is a draft with low-level Browser actions. Refactor it into
business and functional keywords before committing it to a layered project.

## Configuration

| Option | `pyproject.toml` key | Default |
| --- | --- | --- |
| `--output FILE` | `output-dir` | `tests\robot\<name>.robot` |
| `--step-resource FILE` | None | Bundled `Step` library |

The default output directory is read from the nearest parent `pyproject.toml`
and is relative to that file. Without a project file, it is relative to the
current directory. The default directory is created automatically. An explicit
`--output` overrides it, but its parent directory must already exist.

```toml
[tool.rf-browser-recorder-toolbar]
output-dir = 'tests\robot'
```

Names used as filenames must be valid Windows filenames. To use an existing
`Step` keyword instead of the bundled library, pass
`--step-resource "C:\path\to\steps.resource"`; the generated suite imports that
resource using its absolute path.

## Limitations

- Browser records only the active context. Hover is not recorded. Browser's
  other recorder limitations for dialogs, pages and selectors also apply.
- Values made into Browser recorder arguments with defaults become test
  variables. Arguments without defaults must be supplied as Robot Framework
  variables at execution time.

## Troubleshooting

- **Output file already exists:** choose a different name or `--output` path.
- **Output directory error:** check that the destination is writable; an
  explicit output path must have an existing parent directory.
- **Annotation not confirmed:** review the recording before continuing.
- **Browser initialization fails:** check that Node.js is available and run
  `rfbrowser init chromium` in the same environment as the recorder.

## Development

From the project directory:

```powershell
py -3.12 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[dev]"
.\.venv\Scripts\rfbrowser.exe init chromium
.\.venv\Scripts\python.exe -m pytest tests
```

The browser integration test also requires
`$env:RF_BROWSER_RECORDER_TOOLBAR_INTEGRATION = "1"`. In VS Code, the source
project's settings select its `.venv` and start new terminals in the project
folder; existing terminals are unchanged.

Build the distribution with `python -m build`.

## Release

Releases use separate trusted publishers on TestPyPI and PyPI, without API
tokens in GitHub:

1. Register `rf-browser-recorder-toolbar` as a trusted publisher on each index
   (use a pending publisher if the project does not exist yet). Set the owner
   and repository to `sap-robotop` and `rf-browser-recorder-toolbar`. Use
   workflow `publish.yml` and environment `testpypi` for TestPyPI; use
   `publish-pypi.yml` and environment `pypi` for PyPI. Both GitHub environments
   must allow the corresponding workflow.
2. Update the version in `pyproject.toml`, review the source distribution for
   sensitive information, and push a matching tag such as `v0.1.0`. The
   TestPyPI workflow tests, builds and uploads the distribution.
3. Validate the TestPyPI release as described above. In GitHub Actions, manually
   run **Publish approved release to PyPI** from the default branch, providing
   that tag and the successful TestPyPI workflow run ID (visible in its run
   URL). It checks the run and publishes the same build artifacts to PyPI.
   Artifacts expire after 90 days; a published package version cannot be
   replaced.

The manual PyPI workflow is the approval gate; it does not publish automatically
after TestPyPI. Protect the `pypi` GitHub environment and release tags as
appropriate for the repository.

### Validate a TestPyPI release

After publication to TestPyPI, use a fresh environment in a separate working
folder. Install the Browser dependency from PyPI, then install the exact
release from TestPyPI:

```powershell
pip install "robotframework-browser==21.1.0"
pip install --no-deps --index-url https://test.pypi.org/simple/ "rf-browser-recorder-toolbar==0.1.0"
pip check
rfbrowser init chromium
rf-browser-recorder-toolbar --help
```

Replace `0.1.0` and the Browser dependency version with those of the release
being validated. Run a recording as well before approving publication to PyPI.


## License

Apache License 2.0. See [LICENSE](LICENSE).
