Scripts are small pieces of JavaScript that run around a request. A pre-request script runs before the request is built — to set a timestamp, sign something, or pick a value. A test script runs after the response — to check it and to save values for the next request. The runner sends a whole collection or folder, with its scripts and tests, as many times as you like.
Where scripts go
- A request: its Scripts pane, with a Pre-request and a Tests editor. (WebSocket tabs have no scripts.)
- A folder or a collection: Settings… → Scripts. These run for every request inside.
In the editors, Tab inserts two spaces and mod+enter sends the request.
Snippets
Buttons above the editors drop in a ready-made line:
| Editor | Snippets |
|---|---|
| Pre-request | + Set a variable, + Timestamp |
| Tests | + Status is 200, + Faster than 500 ms, + JSON has a field, + Save a token |
With AI turned on, ✦ Write tests writes tests from the request and its last response — see Write tests.
How scripts run
A safe sandbox
Scripts run in a sandboxed frame plus a Worker. They have no network access and no access to DialCatz itself, its storage or the rest of the app — a script can read the request and response and set variables, nothing more.
- Each script is stopped after 10 seconds.
- Top-level
awaitworks, and async tests are awaited.
The order scripts run in
For each request:
- The collection’s pre-request script, then each folder’s from the outside in, then the request’s own.
- The request is built (with any variables those scripts set) and sent.
- The collection’s tests, then each folder’s, then the request’s own.
Each script sees the variables the scripts before it set. Results from outer scripts are labelled Collection X · or Folder Y ·, so you can tell where a test came from.
Variables in scripts
dc.env.set() (and Postman’s pm.environment.set() and friends) change the variables the next steps see. When the
request finishes, the changes are saved into the request’s environment — the collection’s environment or the active
one. With no environment, they go into the globals.
Values are stored as strings: dc.env.set('count', 3) stores "3".
Results
Results show in the response’s Tests tab: PASS or FAIL per test, script errors, Variables set: … and every log line. A failing test or a script error opens that tab on its own.
The dc API
Everything a script needs is on the dc object.
dc.request
Available in both pre-request and test scripts.
| Property | Value |
|---|---|
dc.request.method |
The method, for example "POST" |
dc.request.url |
The URL |
dc.request.headers |
The headers as an object, with lower-case keys |
dc.response
Available in test scripts only.
| Member | Value |
|---|---|
dc.response.status |
The status code, for example 200 |
dc.response.statusText |
The status text, for example "OK" |
dc.response.headers |
The response headers |
dc.response.body |
The body as text |
dc.response.time |
How long the call took, in ms |
dc.response.size |
The size in bytes |
dc.response.json() |
The body parsed as JSON |
dc.response.text() |
The body as text |
dc.response.header(name) |
One header’s value |
dc.env
| Function | Does |
|---|---|
dc.env.get(key) |
Reads a variable |
dc.env.set(key, value) |
Sets a variable (stored as a string) |
dc.env.unset(key) |
Removes a variable |
dc.test and dc.expect
dc.test(name, fn) records a test called name. It passes when fn runs without throwing; fn may be async.
dc.expect(value) checks a value. Its matchers:
| Matcher | Passes when the value… |
|---|---|
toBe(x) |
is exactly x (===) |
toEqual(x) |
deeply equals x (objects and arrays compared by content) |
toBeTruthy() |
is truthy |
toBeFalsy() |
is falsy |
toBeDefined() |
is not undefined |
toBeNull() |
is null |
toContain(x) |
contains x (a string or an array) |
toMatch(re) |
matches a regular expression |
toBeGreaterThan(n) |
is greater than n |
toBeLessThan(n) |
is less than n |
toHaveProperty(path[, value]) |
has the property at a dot path, such as data.user.id — optionally with that value |
toHaveLength(n) |
has length n |
Put .not in front of any matcher to turn it around: dc.expect(body.error).not.toBeDefined().
dc.data and logging
| Member | Does |
|---|---|
dc.data |
The current runner iteration’s data row, as an object |
dc.log(...) |
Writes a line to the log |
console.log, console.info, console.warn, console.error |
Write to the same log |
An example
// Tests on a login request: check it, then keep the token for the next requests
dc.test('logged in', () => {
dc.expect(dc.response.status).toBe(200);
dc.expect(dc.response.json()).toHaveProperty('data.token');
});
dc.test('fast enough', () => {
dc.expect(dc.response.time).toBeLessThan(500);
});
dc.env.set('token', dc.response.json().data.token);
With a secret token variable and Auth set to Bearer token {{token}} on the collection, every other request in it
is now signed in.
Postman scripts (pm)
Scripts imported from Postman keep working: DialCatz understands the common part of Postman’s pm API.
| Postman | Notes |
|---|---|
pm.test(name, fn) |
Same as dc.test |
pm.expect(value) |
Chai-like: .to.equal, .to.eql, .to.include, .to.match, .to.above, .to.below, .to.property, .to.lengthOf, .to.be.ok, .to.be.true, .to.be.false, .to.be.null, and .to.not… |
pm.environment, pm.globals, pm.variables |
get / set / unset — all three map to the same variable store as dc.env |
pm.request |
The request |
pm.iterationData.get(key), .has(key), .toObject() |
The runner’s data row |
pm.response.code, .status, .responseTime |
Status code, status text and time |
pm.response.json(), .text() |
The body |
pm.response.headers.get(name) |
One header |
pm.response.to.have.status(code) |
Asserts the status code |
Because pm.environment, pm.globals and pm.variables share one store, a value set through any of them is saved the
same way as with dc.env.set — into the request’s environment, else the globals.
The collection runner
The runner sends a collection or folder from top to bottom — in tree order — with all its scripts and tests. Variables a script sets are there for the next request, so a login at the top can feed everything after it.
Open it with Run… in the right-click menu of a collection or folder. The dialog, Run “<name>”, says how many requests it holds and which environment it will use.
Set up a run
- Tick the requests to run. A tests badge marks the ones that have tests.
- Data file — Choose CSV or JSON… (
.csv,.tsv,.txtor.json). One iteration per row; its columns become{{variables}}andpm.iterationData(anddc.data). A CSV needs a header row; a JSON file must be an array of objects. - Iterations — 1 to 100, or up to 10,000 with a data file.
- Delay (ms) — a pause between requests, 0 to 60,000.
- Stop on failure — stop at the first failed test or failed call.
A data row’s values win over the environment and the globals for that iteration.
Results
While it runs: Running… N done, with Stop. When it finishes, the cat says All good or Finished with problems, with totals — sent, passed, failed and the total time in ms — and a table:
| Column | Shows |
|---|---|
| # | The iteration |
| Request | Which request |
| Status | Its status code |
| Time | How long it took |
| Tests | Passed / total |
Then:
- Export results — JSON (everything) or JUnit XML (for CI tools).
- Change selection — back to the request list.
- Run again — the same run once more.
Limits
- Scripts have no network access and stop after 10 seconds.
- The runner does at most 100 iterations, or 10,000 with a data file.
- The
pmAPI covers the parts listed above, not all of Postman’s.
Last updated 2026-11-03