Generate and Heal Playwright Tests with Recorded API Traffic
The shop in mock-lab has a Load items button that fetches GET /items and displays apples and pears. In this walkthrough, you’ll use the shop’s recorded API response to generate a Playwright test. Then you’ll rename the button, watch the original test fail, and use proxymock to propose a repair. The shop API stays stopped throughout.
The exercise extends the existing mock-lab browser journeys lab. The companion article explains why a passing test can still be a bad repair.
1. Start the mock-lab storefront
Install Node.js 22 or newer, Git and Make. Install and initialize proxymock and use v2.5.1487 or newer. Ports 3000 and 4140 should be free. Leave the API on port 8081 stopped.
From the directory where you want to clone the repository, run:
git clone https://github.com/speedscale/mock-lab.git
cd mock-lab/labs/browser-journeys
make install
proxymock journeys explore --help
proxymock journeys heal --help
make site
Keep that terminal running. The site loads on http://localhost:3000. Its API calls target http://api.localtest.me:8081, a separate origin. The lab’s recording contains the first-page response, so skip make api and make record. If your network blocks DNS answers that point to 127.0.0.1, add 127.0.0.1 api.localtest.me to /etc/hosts, as the lab README explains.
Prompt for a coding agent
Use the Speedscale mock-lab browser journeys lab at https://github.com/speedscale/mock-lab/tree/main/labs/browser-journeys. Clone it into an isolated directory and work in labs/browser-journeys. Verify Node 22+, Git, Make, initialized proxymock v2.5.1487 or newer, and that proxymock journeys explore --help and proxymock journeys heal --help both work. Run make install and start make site on port 3000 in a managed background process. Keep the shop API on port 8081 stopped. Use the committed recording. Report the commands and anything you could not verify.
2. Generate a Playwright test from the recording
Open a second terminal in mock-lab/labs/browser-journeys. List the recorded sessions and then generate the spec. The lab has one recorded item-list flow, so use the default session selection.
proxymock journeys explore --in proxymock/recording --list
proxymock journeys explore \
--in proxymock/recording \
--url http://localhost:3000 \
--out proxymock/explored-journeys \
--name shop-items
Open proxymock/explored-journeys/shop-items.spec.ts. Look for the button click and the response wait for GET /items. The explorer starts its own mock and uses the recorded response to decide whether the click reached the target call.
Import expect alongside test at the top of the generated file. Inside the step for GET /items, add the following assertion after the response wait so the test also checks what a shopper sees.
await expect(page.getByRole('listitem')).toHaveText(['apple', 'pear']);
Prompt for a coding agent
From labs/browser-journeys, list sessions with proxymock journeys explore --in proxymock/recording --list. Explore the default session against http://localhost:3000 with --out proxymock/explored-journeys --name shop-items. Keep the local shop API stopped. Inspect shop-items.spec.ts and show the action and response wait for GET /items. Import expect and add a Playwright listitem assertion for apple and pear after the response wait. Keep the generated click and wait and tell me which recorded calls were reached.
3. Save a passing replay, then rename the button
In a third terminal in mock-lab/labs/browser-journeys, start the lab mock and leave it running.
make mock
Back in the second terminal, replay your generated spec. Keep the output directory including browser-journey-results.json and its recorded traffic. Heal uses them together to compare the original journey with candidate repairs.
proxymock replay \
--in proxymock/recording \
--browser proxymock/explored-journeys \
--test-against http://localhost:3000 \
--browser-proxy http://localhost:4140 \
--out proxymock/results/heal-baseline
Confirm the summary shows one passing journey before continuing. In app/site/index.html, change the text of the button with id="load" from Load items to Load shop items. Keep the button’s ID and event handler. Stop and rerun make site in the first terminal because the site reads the HTML at startup.
Replay again with a different output directory. This time, look for a timeout at the old locator. Keep the passing baseline for the next step.
proxymock replay \
--in proxymock/recording \
--browser proxymock/explored-journeys \
--test-against http://localhost:3000 \
--browser-proxy http://localhost:4140 \
--out proxymock/results/heal-before-fix
Prompt for a coding agent
From labs/browser-journeys, start make mock on port 4140. Run proxymock replay against http://localhost:3000 with --in proxymock/recording --browser proxymock/explored-journeys --browser-proxy http://localhost:4140 --out proxymock/results/heal-baseline. Confirm one pass and keep the output with its traffic. Change only the id="load" button text in app/site/index.html from Load items to Load shop items, restart the site, and rerun the same replay to proxymock/results/heal-before-fix. Verify the original locator times out. Preserve the baseline and keep the shop API stopped.
4. Review and apply the proposed repair
From the second terminal in mock-lab/labs/browser-journeys, point Heal to the generated spec and the passing replay. Heal starts its own mock for these probes.
proxymock journeys heal \
--in proxymock/recording \
--browser proxymock/explored-journeys \
--url http://localhost:3000 \
--baseline proxymock/results/heal-baseline
Review proxymock/journey-heal.diff. The proposed change should replace the locator’s Load items name with Load shop items. Check that the response wait and the apple-and-pear assertion are intact. Heal accepts a replacement when the whole test passes and its API calls match the passing replay.
Patch paths are relative to the repository root. From the lab directory, run the following:
git -C ../.. apply --check labs/browser-journeys/proxymock/journey-heal.diff
git -C ../.. apply labs/browser-journeys/proxymock/journey-heal.diff
proxymock replay \
--in proxymock/recording \
--browser proxymock/explored-journeys \
--test-against http://localhost:3000 \
--browser-proxy http://localhost:4140 \
--out proxymock/results/heal-after-fix
Look for one passing journey with the renamed button. Compare its GET /items call and list assertion with the baseline. Stop the site and the lab mock when you’re done.
Prompt for a coding agent
From labs/browser-journeys, run proxymock journeys heal with --in proxymock/recording --browser proxymock/explored-journeys --url http://localhost:3000 --baseline proxymock/results/heal-baseline. Show me proxymock/journey-heal.diff and confirm it changes only the old button locator. Use the browser_journeys MCP heal action if available and display the returned diff. Once I approve the patch, check and apply it from the repo root. Replay through the lab mock to proxymock/results/heal-after-fix and confirm the test passes, GET /items is present, and the apple-and-pear assertion survives. Stop the site and mock you started, and report any skipped or failed steps.
Frequently asked questions
Do I need to run the mock-lab API?
Keep the lab API stopped. The frontend loads from its own local server, and proxymock answers the item request from the lab's committed recording.
Why does Journey Heal need a passing replay?
Heal compares every candidate's calls with the newest passing replay for that journey. Keep browser-journey-results.json and the traffic files alongside it.
Can I use a coding agent to generate and heal the test?
Yes. The proxymock MCP tool browser_journeys supports sessions, explore, and heal. The heal action returns a diff you can review and apply.