Skip to content

Add support for HAR file replay for network mocking (routeFromHAR) #4527

@eslamelmishtawy

Description

@eslamelmishtawy

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)

Route Context From HAR
    [Arguments]    path    url=${NONE}    update=${False}    notFound=abort

Example Usage

*** 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions