testgen-agent
v2.0.0
Published
Records and replays Playwright automation and sends API requests for TestGen, from your own machine.
Maintainers
Readme
testgen-agent
Records and replays Playwright automation and sends API requests for TestGen, from your own machine.
It replaces the two helpers that used to do this separately,
testgen-recorder and testgen-api-agent. One process, one terminal.
Why this exists
TestGen runs on a server, and two things cannot happen there:
- Recording a test means driving a real, visible browser. Servers have no screen.
- Sending an API request from the API client has Postman's problem: a web page cannot call an arbitrary origin, and the platform's servers cannot reach a service on your localhost, your intranet, or behind your VPN.
So both happen here, on your machine, in a small process the web app talks to over loopback.
Install and run
npm install -g testgen-agent
testgen-agentLeave that terminal open. The Record button lights up, and the API client's footer shows Agent: this machine.
Or, without installing anything permanently:
npx testgen-agentThe first run downloads the Chromium build its Playwright launches, which takes a minute — and again after an upgrade brings a newer Playwright. After that, startup is instant. Firefox and WebKit are only needed for the devices that ask for them; the app says so when you pick one.
Moving from testgen-recorder
Both listen on the same port, so stop the old one first:
npm uninstall -g testgen-recorder
npm install -g testgen-agentSaved sign-ins live beside the installed package, so the first recording after the switch starts signed out.
What it does
It listens on 127.0.0.1:7337 and answers only the TestGen web app.
Recording. When you click Record, the app asks this process to open a browser; you click through your test; the resulting script goes back to the app and is stored against the test case. Play runs it again in a visible browser.
It also keeps the API calls the page made while you clicked — Playwright's own network log, read once the browser closes — so the app can offer them as a collection in its API client. Stopping from the app closes the browser the way Playwright does it, so that log is kept.
Sending. When you press Send in the API client, the app hands this process the request; it sends it with Node's own HTTP stack and returns the status, headers in arrival order, the body, the cookies the server set, and a timeline of every phase — DNS, connect, TLS, waiting, download. It keeps a cookie jar in memory, exactly like a browser would, and forgets it when it stops.
What it does not do
- It is not reachable from the network. The listener binds to loopback only, so nothing outside your machine can connect to it — not your colleagues, not your network, not the internet.
- It answers one origin. Requests are refused unless they come from the TestGen app itself. A page on any other site cannot use this to open a browser on your machine or send requests into your network, which is the whole reason the check exists.
- It holds no credentials. It never sees your password or your API keys beyond the request you asked it to send.
- It stores nothing. Scripts, collections, history and environments live in TestGen. A file in a form-data body arrives inside the request from the page; the agent is never told a path to open.
Self-hosting TestGen
If you run TestGen on your own domain, tell the agent which origin to accept:
TESTGEN_AGENT_ORIGINS=https://app.your-domain.com testgen-agentComma-separate several. Add only origins you control — this is the check that stops an arbitrary web page driving a browser on your machine.
To listen somewhere other than 7337:
TESTGEN_AGENT_PORT=7400 testgen-agentThe app looks on 7337, so change this only if something else already has that
port. The older TESTGEN_RECORDER_ORIGINS and TESTGEN_RECORDER_PORT are still
read.
Requirements
- Node.js 20 or newer
- A desktop OS with a display for recording — this cannot run on a headless server, which is the reason it is not simply part of the hosted app
Troubleshooting
The app still says the agent is missing. Check the terminal is still open and shows it listening. If you changed the port, the app will not find it.
"Port 7337 is already in use." The older testgen-recorder is probably
still running. Close its terminal and start testgen-agent again.
The API client says the helper on this machine cannot send. That is the
older testgen-recorder, which only records. Replace it with testgen-agent
as above.
"That device needs a browser that is not installed." Run
npx playwright install to fetch the missing engine.
It worked yesterday and now the app says the version is too old. Run
npm install -g testgen-agent again and restart it.
