Browser recording & testing
Record and run browser workflows using optional Playwright support.
On this page
Choose the right working directory. Examples using
npm runshortcuts,node bin/loadstride.js, or top-levelstarter-kit/paths run from the LoadStride source checkout. Those shortcuts do not exist in your application’s package.json. Installed-package users runnpx --no-install loadstridefrom their application directory. See Getting started for both options.
Installed-package quick path
From your application directory, install the optional dependencies and Chromium:
npm install --save-dev loadstride@0.2.0 playwright@1.65.1 acorn@8.15.0
npx --no-install playwright install chromium
Start the included demo application in a separate terminal:
node node_modules/loadstride/starter-kit/auth-server.js
Record the login flow, using the demo credentials demo-user / demo-password:
npx --no-install loadstride record http://127.0.0.1:3001 --out load-tests/browser-flow.mjs
Close the recording browser normally, review the generated script and use the printed input variable names. If username and password were the first two inputs:
LOADSTRIDE_INPUT_1=demo-user LOADSTRIDE_INPUT_2=demo-password npx --no-install loadstride run load-tests/browser-flow.mjs --engine browser --no-env --vus 1 --iterations 1 --headed --report-dir reports/browser
After the visible replay passes, remove --headed for a headless run. Browser
mode supports one fixed-VU workload, with a configurable ceiling (default 20).
Use browser calibration to measure higher concurrency.
Stop the demo server with Ctrl+C afterward.
The source-checkout reference below explains configuration, conversion and limits.
Browser recording and execution (optional)
The HTTP engine has no third-party runtime dependencies. Browser recording and execution use optional Playwright and Acorn packages. Install them from this checkout, followed by Chromium:
npm install --no-save playwright@1.65.1 acorn@8.15.0
npm run browser:install
These are optional peer dependencies; HTTP users do not need them. Browser
binaries are an additional download. Playwright 1.65.1/Chromium was validated
locally; Firefox/WebKit need their own browser installation and are not yet
validated here. Core tests run without these packages; npm run test:browser
runs the optional tests, including real Chromium. CI has a separate browser job.
Browser npm shortcuts (pass additional arguments after --):
| Command | Purpose |
|---|---|
npm run browser:install |
Install Chromium after the optional npm packages |
npm run browser:record -- <url> --out <flow.js> |
Record and generate a LoadStride browser script |
npm run browser:run -- <flow.js> [options] |
Execute a browser script |
npm run browser:import -- <recording.spec.js> --out <flow.js> |
Convert raw Playwright codegen output |
npm run browser:demo |
Run the bundled browser login example; save a new run under reports/browser/ |
npm run test:browser |
Verify LoadStride’s browser implementation; this is the regression suite |
browser:run accepts any script path and selects the browser engine explicitly.
It uses the regular env/config precedence; pass --env-file .env.browser or
--no-env as shown below. browser:demo skips env-file loading and uses the
example’s dummy credentials, with shell variables and CLI overrides still available.
Start the included application in another terminal:
npm run demo:auth-server
Record directly from the command line; no editor extension is needed:
npm run browser:record -- http://127.0.0.1:3001 --out load-tests/browser-flow.js
The browser and Playwright Inspector open. Log in using demo-user /
demo-password, view the profile, and add a demo item. Add assertions in the
Inspector, then close the recording browser normally to finish. LoadStride converts the
recording and prints input variable names. Typed text is replaced with placeholders
in encounter order, such as LOADSTRIDE_INPUT_1 and LOADSTRIDE_INPUT_2; other recorded values,
including URLs, selectors, assertions, selections, and file paths need review.
Do not assume the output is fully sanitized.
The file created by loadstride record is already a runnable LoadStride browser script; it does
not need another conversion. Review its actions, URLs, and assertions, then validate
one iteration with a visible browser. Configure the printed inputs (this example
assumes username and password were the first two typed inputs):
LOADSTRIDE_INPUT_1=demo-user LOADSTRIDE_INPUT_2=demo-password npm run browser:run -- \
load-tests/browser-flow.js --no-env --vus 1 --iterations 1 --headed
After that passes, run a small headless load test and generate both reports:
LOADSTRIDE_INPUT_1=demo-user LOADSTRIDE_INPUT_2=demo-password npm run browser:run -- \
load-tests/browser-flow.js --no-env --vus 2 --iterations 4 \
--report-dir reports/manual
Open the HTML path printed by the CLI in your browser. Its neighboring JSON file
contains machine-readable results. Each --report-dir invocation creates a new
run directory, preserving earlier results. See report output.
To avoid entering inputs on every command, create a local .env.browser file:
LOADSTRIDE_ENGINE=browser
LOADSTRIDE_EXECUTOR=constant-vus
LOADSTRIDE_VUS=1
LOADSTRIDE_ITERATIONS=1
LOADSTRIDE_INPUT_1=demo-user
LOADSTRIDE_INPUT_2=demo-password
Run with that file and omit --no-env:
npm run browser:run -- load-tests/browser-flow.js --env-file .env.browser --headed
npm run browser:run -- load-tests/browser-flow.js --env-file .env.browser \
--vus 2 --iterations 4 --report-dir reports/manual
Use fixed-user settings for browser mode. An existing API .env containing
arrival-rate/stage/scenario settings is incompatible; a dedicated .env.browser
keeps those settings separate. Shell environment values still take precedence over
env files. The local .env.browser file is covered by the existing .env.* ignore rule.
Each input can have a per-VU override, e.g. LOADSTRIDE_INPUT_1_VU_2=demo-user-2.
TARGET_URL or --url replaces the first recorded navigation; later explicit
navigation URLs remain recorded and must be reviewed before targeting another host.
The recorder does not overwrite an existing script. If recording is interrupted or
conversion fails, the incomplete destination is removed and the private raw
recording path is printed for recovery. Raw recordings can contain credentials.
Existing JavaScript from playwright codegen --target playwright-test can also be
converted without executing it:
npm run browser:import -- recordings/flow.spec.js --out load-tests/browser-flow.js
Conversion uses AST parsing and accepts a single generated async test with
page/context fixtures, test/expect imports, and optional service-worker
blocking configuration. Suites, hooks, custom imports/fixtures, device configuration,
and TypeScript require manual adaptation. Raw recordings are limited to 5 MiB.
For a ready-to-run flow without recording:
npm run browser:demo -- --vus 2 --iterations 4
This creates a new run directory under reports/browser/ with JSON and HTML.
The example uses public dummy
credentials and selects demo-user-<vu> automatically. LOADSTRIDE_DEMO_PORT=0 npm run
demo:auth-server can start the demo on an available port; use the printed URL
with --url. An existing server on port 3001 is never stopped automatically.
Browser scripts export options.engine = 'browser' and an async default function:
export const options = {
engine: 'browser', vus: 1, iterations: 1, timeout: '15s',
browser: { type: 'chromium', headless: true, processes: 1, session: 'iteration' },
thresholds: { browser_req_failed: ['rate==0'], browser_page_errors: ['count==0'] },
};
export default async function ({ page, context, expect }) {
await page.goto(process.env.TARGET_URL ?? 'http://127.0.0.1:3001');
await expect(page.getByRole('heading', { name: 'LoadStride login recording demo' })).toBeVisible();
}
expect assertions throw on failure and fail the iteration. LoadStride check, sleep,
metrics, session, and the existing HTTP helper are also available. Browser
cookies/storage belong to Playwright contexts and are separate from the Node HTTP
cookie jar. Default session: 'iteration' creates a fresh browser context and
resets LoadStride session state each iteration. session: 'vu' retains the page, cookies,
storage, and LoadStride state for that VU; use explicit script logic to skip repeated login.
Failed iterations discard the browser context and reset that VU’s LoadStride state.
Browser execution supports the fixed-user executor only, one workload, a default
ceiling of 20 VUs and 1–4 managed browser instances (default 1). Increase the
ceiling explicitly with --browser-max-vus, script browser.maxVUs, or
LOADSTRIDE_BROWSER_MAX_VUS; select instances with --browser-processes,
browser.processes, or LOADSTRIDE_BROWSER_PROCESSES. Each VU has its own context, while contexts
can share a browser instance. Browser instances may spawn multiple OS processes.
These caps are guardrails, not capacity claims. Arrival/ramping executors and
multiple scenarios are rejected for browser mode. Use --headed for visible replay.
--engine browser and LOADSTRIDE_ENGINE=browser select the engine explicitly.
For example, after measuring your workload on the generator machine:
node bin/loadstride.js run load-tests/browser-flow.js --no-env \
--vus 50 --browser-max-vus 50 --browser-processes 2 --duration 30s \
--report-dir reports/browser
The calibrate command measures browser workloads at increasing VU
levels and saves CPU/RAM evidence. capacity offers conditional hardware planning
estimates when repeated measurements support a resource model. See
Browser capacity calibration for commands, acceptance
criteria and limits. These controls were added in 0.2.0; 0.1.0 retains its original 20-VU cap.
Browser network metrics are distinct from http_* helper measurements:
| Metric | Meaning |
|---|---|
browser_reqs |
Observed completed/failed HTTP(S) browser requests |
browser_req_failed |
Fraction of observed requests with transport errors or statuses outside 200–399 |
browser_req_duration |
Request start to response end; monotonic observation fallback if browser timing is unavailable |
browser_data_received |
Encoded response body bytes reported by the browser; unavailable sizes contribute zero |
browser_navigation_duration |
Successful document-navigation request duration; excludes rendering completion |
browser_dom_content_loaded |
Navigation Timing DOMContentLoaded event end, relative to navigation start |
browser_page_errors |
Unhandled page JavaScript exceptions |
These metrics appear in console/JSON/HTML and can have thresholds. Browser assertions are not automatically individual LoadStride checks; generated flows add one completion check. Contexts close on iteration completion, failures, cancellation, and final cleanup. Unfinished requests at context closure count as failed. Await the response or visible application state that defines completion before returning. Service workers are blocked; offline/service-worker behavior is outside this mode. Network metrics do not include WebSockets, external APIRequestContext traffic, or Core Web Vitals such as LCP/INP/CLS. DOMContentLoaded samples may be unavailable if a page is closed before timing collection completes.
Generator event-loop diagnostics measure the Node process and exclude browser process CPU/RSS. Browser VUs use substantially more resources than HTTP VUs; measure the host and target before scaling. Browser startup is outside measured load time; context creation and iteration-level closure are included in iteration time. Final cleanup of retained VU contexts contributes to total elapsed load time. Arbitrary blocking user JS still cannot be forcibly stopped in this shared Node process.
Based on the released v0.2.0 guide. View source on GitHub.