Record your tests
You do not have to write requests. Run what you already have, once, against the old build, and Nikasa saves what it sent as a pack it sends again on every run.
On this page
nk record runs the tests you already have, once, against your old build. It saves the requests they sent as a pack, and every compare sends that pack again to both builds.
You need an app file that starts your app, and a test suite or a collection that talks to it.
Record a pack #
Pick the line that fits your tests. Each one runs against the old build and writes the pack to nk/packs/main, where a plain nk compare myapp:old myapp:new picks it up.
Run your test tool as it is #
Run the command in the folder shown. You need no command of your own.
| Your tests | Run in | Command |
|---|---|---|
| Playwright | The folder holding its config | nk record myapp:old nk/ |
| Cypress | The folder holding its config | nk record myapp:old nk/ |
| Bruno | The collection's folder, the one holding bruno. |
nk record myapp:old nk/ |
| Postman | The collection's folder, the one holding a *. |
nk record myapp:old nk/ |
Run your own command #
Your command in a container on the sandbox network. This folder is at /work inside it:
nk record myapp:old nk/packs/main out/record --app nk/app.yaml \
--driver-image mcr.microsoft.com/playwright:v1.56.0 -- npx playwright test --workers 1Your command on this machine, against a port nk publishes to it only:
nk record myapp:old nk/packs/main out/record --app nk/app.yaml --on-host -- npm run e2eYour command finds the app's address in $NK_HOST and $BASE_URL.
Click through it yourself #
Leave out the command, and you drive your own browser. nk prints the address and waits for Enter:
nk record myapp:old nk/packs/main out/record --app nk/app.yaml --on-hostKeep the pack somewhere else #
Name a pack kept anywhere else with --pack:
nk compare myapp:old myapp:new out --app nk/app.yaml --pack packs/checkoutTo have a CI job record your tests on every pull request instead, see Your tests drive the compare.
Give your tests what they need #
Nikasa starts your app from the compose file, with nothing in it yet. Your tests often expect things your CI sets up first: a user, a setting on the app, a variable.
Say them once in the app file, and nk record needs no flags:
services:
app:
environment:
SIGNUPS_OPEN: "true" # a setting the app needs for your tests
x-nk:
host: http://app:3000
tests:
driver: playwright # or cypress, newman, bruno
folder: packages/e2e # where the suite is, from where you run nk record
setup: npm run build:fixtures # a shell line, after the install
args: [tests/api, --grep, smoke] # words for the test tool, such as which tests to run
env: # what the test tool gets in its environment
E2E_USER: admin
E2E_PASSWORD: ${E2E_PASSWORD} # ${NAME} or $NAME comes from this machine's environmentThen run:
nk record myapp:old nk/packs/main out/record --app nk/app.yamlWhat each key does #
| Key | What it does |
|---|---|
driver |
The test tool to run: playwright, cypress, newman or bruno. |
folder |
Where the suite is, from where you run nk record. |
setup |
A shell line that runs after the install. |
args |
Words for the test tool, such as which tests to run. |
env |
What the test tool gets in its environment. |
The block is used with its driver or with --driver. --driver-image and --on-host run your command instead, and nk record says in one line that the block is not used. With no driver and no command, its message names the block.
Change one run without editing the file #
--driver replaces driver, and words after -- replace args. So this tries one folder:
nk record myapp:old nk/packs/main out/record --app nk/app.yaml --driver playwright -- tests/apiThe printout names what it took from the file, by setting name and never by value.
Dollar signs and secrets #
Compose reads this block too, so a dollar sign follows its rule: write $$ for one, in env, args and setup alike.
| Where | What ${NAME} and $NAME do |
|---|---|
env |
Take the value from this machine's environment. nk record stops if it has none. |
setup |
Are left for the shell in the driver container, which has what env gives it. |
Find what your tests need #
Read the CI job that runs them. Its environment and the steps before the tests are usually the whole list.
A database user or row belongs in --seed "<command>". See Start from real data.
Read what nk record says #
When it finishes, nk record prints how your tests did:
your tests while recording: 42 passed, 3 failed, 1 skipped; the pack holds what they sent, and out/record/driver.log says why the others did not pass
left out 74 static files and 9 event streams, as a replay has no browser to use the files and would wait on the streams for everA test that fails still leaves its requests in the pack, and a compare covers whatever they reached.
When most tests did not pass, or most requests were answered with an error, nk record says so, because that recording covers little. The counts are in pack.json and in the report's provenance.
In CI #
The job nk init --ci writes records from the base branch's checkout. So folder is read there, and a suite added in the same pull request is first recorded on the next one.
Your CI's secrets reach env through the job's environment.
What a pack holds #
Nikasa captures the requests, and works out which later request reuses a value an earlier response made, such as a login token or the id of something just created. It writes these files:
| File | Holds |
|---|---|
inputs/ |
Every request in order, as Hurl you can read and edit. Each reused value is captured where it is made and sent on as a variable, so every run gets fresh ones. |
links. |
Those links, kept apart from the recording. |
raw/ |
The requests the pack keeps, exactly as captured, never edited. |
pack. |
Nikasa's version, the image and its digest, the command, and a self-check. |
The self-check sends the pack twice against the old build, and lists any request answered differently.
A suite whose tests each start with no cookies gets one file for each start: session_00002.hurl and on, run in that order.
A pack also keeps your app's outside calls.
What a pack leaves out #
A compare from a pack sends the old build's requests again and drives no browser. So these stay out of the pack, and nk record counts them, as in the output above:
- the files a browser fetched to draw its pages;
- the event streams it opened or tried to open;
- its
if-none-matchandif-modified-sincequestions, which are not sent again.
What a test asks for itself stays, an image too. A call that only the new build's front end makes is not exercised.
What is not rewritten #
- What a client says about itself, such as its
user-agent, is not linked or rewritten. - A cookie the jar sends is left to it.
- A value sent in a multipart form is linked like one in any other form.
- A large recorded answer is kept as a file beside the pack's steps.
Cookies and sessions #
Requests sent again from a pack share one cookie jar for each .hurl file. So a test that started with no cookies would be sent the last test's login.
Nikasa starts a new file where the recording left the old cookies behind for good: no later request sends them.
Hurl's variables stay in their file too. A value a later file reuses is sent as recorded, which holds for names, paths and small ids on an app started the same way. A UUID or a long token cannot be sent again, so it keeps its files together.
Sessions that really overlap, such as two browsers open at once or parallel workers, share a file and its jar. The pack's self-check lists what that changes.
Keep a pack elsewhere #
--pack also takes a pack kept somewhere else, fetched into <out-dir>/pack before the first run. It takes:
- A link (
https://...) to a.tar.gzor.zipof the pack folder, such as a presigned link or a CI artifact. Nikasa prints the link without its query, so a signature stays out of your logs. - An S3 path:
s3://bucket/packs/checkout.tar.gzfor an archive, ors3://bucket/packs/checkout/for the folder itself. It is copied with the AWS CLI on the machine, with whatever credentials it already uses.
Nikasa prints the archive's SHA-256, so a report can be traced to the exact pack. Make an archive with:
tar -czf checkout.tar.gz -C packs/checkout .What each suite needs #
Each test tool has its own rules. Find yours below.
Playwright and Cypress #
Both install the suite's packages with the tool of the nearest lockfile at or above the suite's folder, up to the top of the repository:
npm cipnpm install --frozen-lockfileyarn install(Classic, or Berry leaving anode_modulesfolder)bun install
None of them runs the packages' install scripts. The pnpm version is the one packageManager names, else the one that writes the lockfile's format.
A monorepo works: the lockfile's whole folder is copied and installed, and the suite runs from its own folder. A folder with no lockfile at or above it is refused before anything starts.
Playwright #
- Nikasa reads your
@playwright/testversion frompackage-lock.json,pnpm-lock.yaml,yarn.lockorbun.lock, and runs the matching official image.--driver-versionpicks another. - It installs on a copy of your project and runs your own config, with the app's address set on every project and
webServerleft out. - Inside the driver container,
localhost:<the app's port>forwards to the app. So addresses your tests write as localhost, Secure cookies andcrypto.subtlework as on your machine.--no-relayturns that off.
Cypress #
- Nikasa reads your
cypressversion the same way, and runs the matchingcypress/includedimage. It installs on a copy of your project, as it does for Playwright. - It runs
cypress runin Electron withbaseUrlset to the app's address, no video, no failure screenshots and no retries. localhostforwards as with Playwright.
A baseUrl set in setupNodeEvents, an address written into a test, and retries set on a single test are not changed.
Bruno #
- Nikasa runs
bru runon a copy of the folder withbaseUrlset to the app's address, in the official image for your@usebruno/cliversion. - The collection reaches the app by its name on the sandbox network.
--relaymakeslocalhost:<the app's port>forward to it instead. - When the folder has a
package.json, Nikasa runsnpm ciand Bruno's developer sandbox, so scripts can use your packages and run any code in the driver container.
A host kept in a variable or written into a request is not changed by baseUrl.
Postman #
Export the collection as Collection v2.1.
- Nikasa runs
newman runon a copy of it withbaseUrlset to the app's address. - It uses an image it builds on your machine the first time, which needs network once.
--driver-versionpicks another newman. - Only the collection is used, not a data file or an environment file.
A host written into a request or set by a script is not changed.
Next steps #
- Your first compare: compare your old build with a new one, using the pack you recorded.
- The app file: where the
testsblock lives. - Start from real data: seed the database your tests expect.
- Outside services: what happens to your app's calls to other services.
- Other inputs: gRPC, queues and scheduled jobs.
Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.