Guides
Network mocking and HAR
Mock endpoints inline, or record and replay traffic so suites run offline.
What you'll learn
How the mock step answers requests with inline JSON, how @har:<name> records and replays network traffic per environment, how strict and offline modes work, and how API-layer scenarios replay without a browser.
Inline mocks
When I mock "**/api/banner" with JSON:
"""json
{ "text": "Welcome {{username}}" }
"""HAR record and replay
@ui @smoke @har:products
Scenario: Products render from recorded traffic
Given I am on the inventory page
Then I should see the text "Sauce Labs Backpack"bun run automax har record -p demo-shop -e staging -t @har:products # update mode
bun run automax har replay -p demo-shop -e staging --strict # abort on any request not in the file
bun run automax har list -p demo-shop| Mode | AUTOMAX_HAR_MODE | Behaviour |
|---|---|---|
| off | off | no HAR routing |
| update | update | requests go to the network and the file is rewritten |
| replay | replay (default when the file exists) | responses come from the file; misses fall through unless :strict or --strict |
AUTOMAX_OFFLINE=1 additionally aborts every request the HAR does not answer, which is how CI proves a suite has no hidden network dependency.
API layer
Playwright's routeFromHAR only exists for pages and browser contexts, so the API client implements its own recorder and replayer keyed by method, normalised URL and body hash. The same @har:<name> tag drives both.