MarketSquare / MarketSquare/robotframework-browser
Add support for HAR file replay for network mocking (routeFromHAR)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 655
- Forks
- 147
- Avg merge
- 5h 27m
- Merged PRs (30d)
- 59
Description
**Is your feature request related to a problem?**
I need to mock API responses for testing but Robot Framework Browser only supports **recording** HAR files, not **replaying** them. Currently, I can record network traffic with `recordHar` in `New Context`, but there's no way to use that HAR file to mock responses in subsequent test runs.
This means I cannot:
- Test applications offline with previously recorded traffic
- Create reproducible tests with consistent API responses
- Mock backend APIs while testing frontend independently
**Describe the solution you'd like**
Expose Playwright's `routeFromHAR()` functionality through new Robot Framework keywords. Playwright already supports this - it just needs to be exposed.
### Proposed Keywords
**2. Route Context From HAR** (context-level)
```robot
Route Context From HAR
[Arguments] path url=${NONE} update=${False} notFound=abort
```
### Example Usage
```robot
*** Test Cases ***
# Step 1: Record HAR (first run)
Record API Traffic
${har} = Create Dictionary path=./api.har
New Context recordHar=${har}
New Page https://example.com
Click text=Load Data
# Network traffic recorded
# Step 2: Replay HAR (subsequent runs)
Test With Mocked Data
New Context
Route Context From HAR path=./api.har url=**/api/**
New Page https://example.com
Click text=Load Data
# Requests to /api/** served from HAR file (offline, fast, consistent)
```
**Additional context**
- **Playwright Documentation**: https://playwright.dev/docs/mock#replaying-from-har
- **Playwright API**:
- [`page.routeFromHAR()`](https://playwright.dev/docs/api/class-page#page-route-from-har)
- [`browserContext.routeFromHAR()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-route-from-har)
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
Start by tracing the existing New Context implementation and its recordHar handling, then compare the requested keyword with Playwright's browserContext.routeFromHAR API and the linked replay documentation. Implement the context-level Route Context From HAR arguments shown in the issue, and verify that matching requests are replayed with the specified url, update, and notFound options.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100