MarketSquare / MarketSquare/robotframework-browser
New Context recordHar with a relative path writes the HAR into the wrapper directory, also on the Robot Framework path
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 655
- Forks
- 147
- Avg merge
- 5h 27m
- Merged PRs (30d)
- 59
Description
A relative `recordHar` path is passed to the Node side verbatim and is resolved against the Node process's working directory — the wrapper directory inside the installed package. The HAR file is written there instead of under `${OUTPUTDIR}`.
**This affects ordinary Robot Framework runs**, not only keywords called from Python. `recordHar` never passes through `outputdir`, so an absolute `${OUTPUTDIR}` does not protect it.
### Reproduce
```robotframework
*** Settings ***
Library Browser
*** Test Cases ***
Record Har With A Relative Path
New Browser webkit headless=True
New Context recordHar={"path": "relative_from_robot.har"}
New Page ${PAGE_URL}
Get Title == HAR lab
Close Context
Close Browser ALL
```
Run with `robot --outputdir out har.robot`. Observed:
```
Browser/wrapper/relative_from_robot.har 1540 bytes <- actual location
out/ <- no .har anywhere
/ <- no .har
```
The test passes, so nothing signals that the file went somewhere unexpected. In a normal (non-editable) install this writes into `site-packages`.
### Cause
`recordHar` is never touched on the Python side — it appears only in the keyword signature and documentation (`Browser/keywords/playwright_state.py:607,649,752`) and is forwarded to Node as given. The Node process runs with `cwd=self._browser_wrapper_dir` (`Browser/playwright.py:280`, passed to `Popen` at `:104`).
Compare `recordVideo`, which is resolved before being sent (`Browser/keywords/playwright_state.py:948-960`) and therefore behaves correctly.
### Suggested fix
Resolve the `recordHar` path in `_set_context_options` the same way `recordVideo`'s directory is resolved, so a relative path lands under `outputdir`.
### Environment
Browser 20.3.0, Robot Framework 7.4.1, Python 3.14.7, macOS, webkit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect Browser/keywords/playwright_state.py, especially _set_context_options and the recordVideo handling around lines 948-960, then compare the recordHar paths at lines 607, 649, and 752. Check Browser/playwright.py lines 280 and 104 to understand the Node working directory, reproduce with the provided Robot Framework case, and verify that a relative HAR path is written under outputdir.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- playwright, python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100