Skip to main content

Test a frontend from local recording to Cloud replay

This walkthrough uses the browser journeys lab in mock-lab: a one-page shop whose Load items and Next page buttons call a separate API. You replay its Playwright journeys with the API answered from a recording, read two failures that look alike, catch a backend change, heal a renamed button, and run the same journeys in a cluster with a Speedscale Cloud report. The blog post Playwright end-to-end testing with recorded API mocks tells the same story with more background, and Generate and heal Playwright tests goes deeper into heal.

Start the lab​

Use Node.js 22 or newer, make, and an installed and initialized proxymock CLI.

git clone https://github.com/speedscale/mock-lab.git
cd mock-lab/labs/browser-journeys
make install

make install installs @playwright/test and Chromium in the lab directory, where proxymock finds them. Start the frontend and leave it running:

make site

The shop loads on http://localhost:3000. Its API runs on http://api.localtest.me:8081, a public name that resolves to 127.0.0.1, so the API has its own origin. If your network blocks that answer, add 127.0.0.1 api.localtest.me to /etc/hosts.

The lab's demo shop after a click on Load items: the heading Demo shop SPA, the Load items and Next page buttons, and the items apple and pear

Coding agent prompt

Clone speedscale/mock-lab into a scratch directory, run make install in labs/browser-journeys, and start make site in a managed background process. Check that http://localhost:3000 serves the shop. Keep the API on port 8081 stopped.

Record a journey​

The lab ships a recording in proxymock/recording, so you can skip this step. To record your own, start the API with make api in a second terminal, then run:

make record

This runs proxymock record --browser http://localhost:3000, which opens Chromium with Playwright's code generator. Click Load items, then close the window. proxymock writes the API calls and a generated journey under proxymock/my-recording. The browser sends every request through the recording proxy, including the CORS preflight before the cross-origin GET /items. Open the recording to check it:

proxymock web --in proxymock/recording

proxymock web's Requests grid for the lab recording: two outbound calls to api.localtest.me /items, an OPTIONS preflight answered 204 and a GET answered 200, plus the page load and favicon from localhost

The generated spec clicks but asserts nothing. journeys/items.spec.ts is the same click with a named step and an expectation. Add RECORDING=proxymock/my-recording to the make commands below to use your own recording, and stop the API before the next step.

Replay with the API stopped​

Start the mock server in a second terminal:

make mock

It runs proxymock mock --in proxymock/recording --no-passthrough, so a call the recording cannot answer gets a 404 instead of reaching a real host. In a third terminal, replay the journey:

make replay
✓ shopper loads the item list (items.spec.ts:3) 272ms

Browser journeys: 1 passed, 0 failed, 0 skipped
Web vitals (p95 across journeys): LCP 32ms, FCP 32ms, TTFB 8.8ms, CLS 0

The journey passes with nothing listening on port 8081. make replay runs proxymock replay --browser journeys --test-against http://localhost:3000 --browser-proxy http://localhost:4140: --test-against is the frontend, and --browser-proxy sends the browser's API calls to the mock server.

Tell two failures apart​

journeys-failing/ adds two journeys that fail on purpose. With the site and the mock server still running:

make replay-failing
✓ shopper loads the item list (items.spec.ts:3) 177ms
✗ shopper sees a checkout button (checkout.spec.ts:5) 3.189s
Error: expect(locator).toBeVisible() failed
✗ shopper pages through the items (next-page.spec.ts:4) 3.159s
Error: expect(locator).toHaveText(expected) failed
not in the recording: GET http://api.localtest.me:8081/items?page=2

Browser journeys: 1 passed, 2 failed, 0 skipped

Both journeys are red, but the evidence differs. shopper sees a checkout button made only calls the recording answered, so the page itself has no Checkout button. shopper pages through the items made a call the recording does not have. Open proxymock web --in proxymock and pick the run under Run. The Report view sorts each failure into its likely cause, and the Journeys view shows each step with the calls it made.

proxymock web's Report view for the failing run: 2 failures, one App regression for shopper sees a checkout button and one Mock gap for shopper pages through the items

Catch a backend change​

Now send the same journey to the real API and compare its answers with the recording. Stop make mock, then start the API and the mock server in observe mode in two terminals:

make api
make mock-real

make mock-real runs proxymock mock --in proxymock/recording --observe-real-apis. make replay passes. Now stop make api and start the API with a field renamed:

make api-changed
make replay

With the frontend unchanged, the journey fails and names the call:

✗ shopper loads the item list (items.spec.ts:3) 5.21s
answered differently from the recording: GET http://api.localtest.me:8081/items (Body JSON)
Browser journeys: 0 passed, 1 failed, 0 skipped

In proxymock web, the Journeys view puts the changed call under the click that made it, and the failed expectation shows the list rendered undefined for each item.

proxymock web's Journeys view for the run against the changed API: the expectation received undefined twice instead of apple and pear, and under the click on Load items the call GET http://api.localtest.me:8081/items is flagged as answered differently from the recording (Body JSON)

Stop the API and the mock server when you finish. make verify-local runs the last three sections in one go and checks each result.

Coding agent prompt

In the browser journeys lab, run the mocked replay, the failing replay, and the observe-mode replay against make api-changed. For each failed journey, report whether a call was missing from the recording, answered differently by the real API, or not involved, and quote the line proxymock printed.

Heal a renamed button​

A redesign that renames a button breaks the journey's locator even though the flow still works. Heal compares against a run where the journey passed. Save one in a fresh folder: with the API stopped, start make mock, then run:

proxymock replay --in proxymock/recording --browser journeys \
--test-against http://localhost:3000 --browser-proxy http://localhost:4140 \
--out proxymock/results/heal-baseline

The journey passes. Stop the mock server. make replay adds every run to proxymock/results/journeys, which is why the baseline gets a folder of its own.

Now change the text of the button with id="load" in app/site/index.html from Load items to Load shop items, and restart make site. Ask proxymock to repair the journey against the passing run:

proxymock journeys heal --in proxymock/recording --browser journeys \
--url http://localhost:3000 --baseline proxymock/results/heal-baseline
shopper loads the item list (items.spec.ts): healed
failed step: Click getByRole('button', { name: 'Load items' }) at items.spec.ts:8
the journey passes and makes the same API calls as in the run where it last passed
tried page.getByRole('button', { name: 'Load shop items', exact: true }): accepted
- await page.getByRole('button', { name: 'Load items' }).click();
+ await page.getByRole('button', { name: 'Load shop items', exact: true }).click();
checked against proxymock/results/heal-baseline, where the journey made GET /items
Patch: journey-heal.diff

Heal accepts a locator only when the journey passes with it and makes the same API calls as in the passing run. It changes nothing until you apply journey-heal.diff with git apply or run heal again with --write, and with --pr it opens a pull request instead. Leave the patch unapplied here: put the button text back to Load items and restart make site before you continue. See Explore and heal journeys.

Read the runs in Speedscale Cloud​

The lab can create a disposable minikube cluster with the released Speedscale operator and deploy the shop and its API. It needs minikube, a container runtime with about 6 GB free, kubectl and helm, plus your API key:

export SPEEDSCALE_API_KEY=<key>
make up

Run the failing journeys with the snapshot and report in Speedscale Cloud:

make cloud-failing

This runs proxymock cluster replay start --browser journeys-failing --snapshot-source cloud against http://shop-spa.browser-journeys:80. The recording and journeys are pushed as a snapshot, and a generator pod runs Chromium with a responder beside it that answers the frontend's API calls. The command prints a report at: link and returns before cloud analysis finishes, so wait for the report's status to change to Passed or Missed Goals before you open its Journeys tab.

The Journeys tab of a Speedscale report with one passed and two failed journeys and p95 web vitals. The passed journey is expanded to show its steps, each with its category, duration and the number of calls it made

Expand shopper pages through the items. The click on Next page names the call the recording could not answer, one step before the assertion times out.

The failed journey expanded: under the click on Next page, the tab says Not in the recording, so the mock could not answer, and names GET http://api.localtest.me:8081/items?page=2. The expect step after it shows the failed assertion

Under a failed journey's steps are the screenshot Playwright took when it failed and the files it kept. Open trace replays the journey in Playwright's trace viewer inside the dashboard.

A failed journey&#39;s files in the Journeys tab: the screenshot of the demo shop with no Checkout button, an Open trace button and downloads for the screenshot, error context and trace

The trace viewer open in the dashboard on the failed journey shopper sees a checkout button, with the action list, a snapshot of the page and the failed toBeVisible expectation

Now change the API in the cluster and run with mocks off, so the report compares the real API's answers with the recording:

make change-api
make cloud-real

The Journeys tab for the run with mocks off: under the click on Load items, GET http://api.localtest.me:8081/items is named as answered differently from the recording by the real API, with Body JSON as what differed

Restore the API with make restore-api, and remove the cluster with make down when you finish.

To start the same replay from the dashboard, open /replay-launcher?snapshotId=<snapshot id> with the snapshot id the command printed and pick Browser journeys under Start from; see From the dashboard. To start it with a Speedscale Cloud login and no kubeconfig, use proxymock cloud replay, with --cluster set to the cluster's name in Speedscale Cloud:

proxymock cloud replay --in proxymock/recording --browser journeys-failing \
--cluster "$DEMO_CLUSTER" -n browser-journeys \
--target http://shop-spa.browser-journeys:80 --wait

Add --no-mocks to send the frontend's calls to the real API. See Run journeys in a cluster.

Coding agent prompt

Run the lab's failing journeys in the cluster with a Speedscale Cloud report, then run them with mocks off after make change-api. From each report's Journeys tab, name the step and call behind every failure, and restore the API when you finish.

Run the journeys in CI​

Copy labs/browser-journeys into a repository of its own. The proxymock GitHub Action and GitLab component run browser journeys when browser names the journeys directory. They answer the frontend's API calls from the recording, install the browsers, and keep the traces and screenshots with the job's artifacts. Install the lab's Playwright dependency first, so the browsers match it:

- uses: actions/checkout@v4
- run: npm ci
- uses: speedscale/proxymock-action@v1
with:
api-key: ${{ secrets.SPEEDSCALE_API_KEY }}
in: proxymock/recording
app-command: node app/serve-site.js
app-port: 3000
browser: journeys

proxymock ci init github --in proxymock/recording --browser journeys --app-command "node app/serve-site.js" --app-port 3000 writes the workflow for you, and gitlab in place of github writes the GitLab job. Add --dry-run to print it first, or --heal to open a pull request with healed locators when a journey fails because its element moved. The same pipeline can review changed screenshots in a pull request, run against preview deployments, and report a check on the commit. See Browser journeys in CI/CD.

Go further​

Each of these works with the lab's recording and journeys:

  • Run more browsers and devices. Add --browser-engines chromium,firefox,webkit or --browser-devices "iPhone 15", retry flaky journeys, record video and shard across CI jobs. See Playwright config and run settings.
  • Scan for accessibility problems. Install @axe-core/playwright and add --browser-a11y to scan every page the journey shows. Add --browser-a11y-fail-on serious to fail the journey on serious violations. See Accessibility scans.
  • Compare screenshots. Add toHaveScreenshot() to the step and review changed images in a pull request. See Screenshots and ARIA snapshots.
  • Track flaky journeys. proxymock journeys history ranks journeys by how often they pass, and proxymock journeys quarantine stops a flaky one from failing the run. See Compare runs and Quarantine flaky journeys.
  • Start signed in. Reuse a storage state, mint fresh tokens, sign in as several roles, and fill authenticator codes, passkeys and single sign-on. See Start signed in.
  • Write journeys without a recorder. Explore a recorded user session, describe a journey in plain language, or let a model recover from a moved element during the run. See Explore and heal journeys.
  • Hand the work to a coding agent. The proxymock MCP server's replay tools run journeys, and the browser-journey-tests skill teaches an agent to write them. See From a coding agent. The Playwright gates lab shows an agent porting an existing suite.

Loading search...