Metadata-Version: 2.4
Name: robosapiens-sapguirecorder
Version: 0.1.1
Summary: Desktop toolbar that records SAP GUI actions with RoboSAPiens and saves them as Robot Framework tests with steps and comments.
Author: Ken DEFOSSEZ
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/sap-robotop/rf-sapguirecorder
Project-URL: Issues, https://github.com/sap-robotop/rf-sapguirecorder/issues
Keywords: robotframework,robosapiens,sap,sapgui,recorder,test automation
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Win32 (MS Windows)
Classifier: Environment :: X11 Applications :: Qt
Classifier: Framework :: Robot Framework
Classifier: Framework :: Robot Framework :: Tool
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
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 :: Testing
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: robotframework>=7.0
Requires-Dist: robotframework-robosapiens==2.31.0
Requires-Dist: PySide6-Essentials<7,>=6.8
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Dynamic: license-file

# robosapiens-sapguirecorder

A floating desktop toolbar that records your actions in an open SAP GUI session
with [RoboSAPiens](https://github.com/imbus/robotframework-robosapiens) and saves
them as a [Robot Framework](https://robotframework.org) test. You can add
**steps** and **comments** while you record; they are inserted at the right
place in the saved `.robot` file.

## Prerequisites

- Windows with an interactive desktop and SAP GUI installed.
- SAP GUI scripting enabled on both the client and the server.
- Python 3.11 or newer.
- An approved non-production SAP session open at the screen where you want to
  start recording.

The toolbar drives the RoboSAPiens **2.31.0** recorder command line (its
`start`, `stop`, `save` and `exit` prompts, the `--debug` event output and the
HTML report). The dependency is therefore pinned to
`robotframework-robosapiens==2.31.0`.

## Install

```powershell
pip install robosapiens-sapguirecorder
```

To install the latest development version from GitHub:

```powershell
pip install "git+https://github.com/sap-robotop/rf-sapguirecorder.git"
```

This installs RoboSAPiens, Robot Framework and PySide6 (the toolbar UI).

## Record a test

With the intended SAP session open:

```powershell
sapgui-recorder --name my_test
```

(`python -m sapguirecorder --name my_test` is equivalent.)

1. Select **Start**.
2. Before the actions of a logical step, type its label and select
   **Add Step** (or press Enter). Then perform those actions in SAP GUI.
3. To add a Robot comment, type it in the comment field and select
   **Add Comment**.
4. Wait for each SAP action to finish before adding the next step or comment.
5. Select **Stop**, then **Save & Exit**.

The **Logs** box shows each step, comment and SAP action as it happens:

```text
Step 1: Enter Tcode
Action: Execute Transaction    se16n
Action: Press Key Combination    Enter
Step 2: Enter Table name
Action: Fill Text Field    Where-Used list: Table    PA0105
```

Steps and comments are placed automatically by comparing their click times with
the action timestamps in the RoboSAPiens report. If that cannot be verified,
the toolbar asks where to place each one (before an action, at the end, or
unplaced). Popup closes (`Close Window`), which RoboSAPiens 2.31 sees but does
not write, are inserted by the toolbar.

Names must be 1-80 ASCII letters, digits, `_` or `-`, start with a letter or
digit, and must not be Windows device names such as `CON`. Existing captures
are never overwritten.

The recorder has no session picker: close other SAP sessions to avoid
recording the wrong one. Avoid recording passwords or sensitive data.

## Output

| File | Contents |
| --- | --- |
| `<name>.robot` | Header from the template (if any), recorded actions, steps and comments |
| `<name>.html` | Original RoboSAPiens report, including screenshots |

Steps use the `Step` keyword from the bundled library `sapguirecorder.steps`,
which is imported automatically when needed. Actions after a step are indented
for readability:

```robotframework
*** Settings ***
Library    sapguirecorder.steps
Library    RoboSAPiens    x64=True

*** Test Cases ***
my_test
    Connect to running SAP
    Step    Open transaction
        # Verify the expected program is selected
        Execute Transaction    SE38
```

After saving, the terminal prints `Saved Robot file: <path>` and the final log
on stderr, and a JSON result on stdout
(`{"status": "saved", "robot": ..., "html": ..., "unplaced_steps": 0, ...}`).
Exit codes: `0` saved, `2` cancelled, `1` error.

The HTML report can contain screenshots and SAP window titles; keep captures
local and review them before sharing.

## Configuration

| Option | `pyproject.toml` key | Default |
| --- | --- | --- |
| `--output-dir DIR` | `output-dir` | current folder |
| `--robot-template FILE` | `robot-template` | `00_template.robot` in the output folder, if present |

Settings are read from the `[tool.sapguirecorder]` table of the nearest
`pyproject.toml` (searching from the current folder upwards); paths are
relative to that file. Command-line options take precedence. Unknown keys are
rejected so typos are not silently ignored.

```toml
[tool.sapguirecorder]
output-dir = "tests/recordings"
# Robot file whose *** Settings *** section (resources, libraries, variables,
# setups, teardowns, tags) becomes the header of every recording.
robot-template = "tests/recordings/00_template.robot"
```

### Header template

A template is a Robot file with a `*** Settings ***` section followed by an
empty `*** Test Cases ***` section:

```robotframework
*** Settings ***
Library           RoboSAPiens    x64=True
Library           sapguirecorder.steps
Suite Setup       Connect To Running SAP
Test Tags         sapgui    recorded


*** Test Cases ***
```

The generated file is the template header, verbatim, followed by the recorded
test case with the toolbar's steps, comments and actions:

- Every recorded `*** Settings ***` line (`Library    RoboSAPiens    x64=True`,
  `Test Setup    Open SAP ...`) is discarded; the template owns imports,
  variables, setups and the SAP connection.
- The leading `Connect to running SAP` action that RoboSAPiens always records
  is dropped, because the template's setup owns the SAP connection. Without a
  template it is kept.
- The template must make the `Step` keyword available, either with
  `Library    sapguirecorder.steps` or through a resource defining `Step`.

Without a template, the raw RoboSAPiens settings are kept and
`Library    sapguirecorder.steps` is added when steps were placed.

An explicitly configured template must exist; the default one is optional.

## Pausing

RoboSAPiens 2.31 does not support pause/resume: `start` after `stop` creates a
new recorder. Save each segment under a new name and combine them manually.

## Troubleshooting

- **Capture already exists:** choose a new name (`.robot`, `.html`, and legacy
  `.robot.raw` / `.steps.json` files block reuse).
- **Invalid template:** it must contain Settings followed by an empty Test
  Cases section.
- **Cannot lock the Recorder folder:** close the other toolbar and check that
  the output folder is writable.
- **Finalizing failed:** the original RoboSAPiens file is left unchanged. Use
  **Show Details** to copy your steps and comments.
- **Automatic placement unavailable:** place the annotations in the dialogs and
  review the saved file.

## Development

```powershell
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[test]"
.\.venv\Scripts\python.exe -m pytest
```

Build the distribution with `python -m build`.

## Release

Releases are published to PyPI by the `Publish` workflow using Trusted
Publishing. Bump `version` in `pyproject.toml`, commit, then push a matching
tag:

```powershell
git tag -a v0.1.1 -m "v0.1.1"
git push origin v0.1.1
```

The workflow runs the tests, builds the distributions, publishes them to
TestPyPI, then to PyPI. It fails if the tag does not match the version.

## License

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