Scripts & Automation
Full scripting engine with pre-request and test scripts, Postman-compatible vx/pm API, assertions, variable manipulation, and console output.
Pre-Request Scripts
Scripts that run before the request is sent. Written in JavaScript with a dedicated code editor (syntax highlighting, line numbers, gutter). Use them to:
- Set dynamic headers or parameters
- Generate timestamps, UUIDs, or random values
- Log debug information to the console
- Conditionally modify the request
Test / Post-Response Scripts
Scripts that run after the response is received. Use them to:
- Extract values from the response and save as cluster variables
- Validate response status codes, headers, and body structure
- Chain requests by passing data between them via variables
- Run assertions — results appear in the Tests tab of the response viewer
The vx API Reference
VortexHQ provides a global vx object in all scripts:
Response Access
vx.response.code // HTTP status code (number)
vx.response.status // Same as .code
vx.response.headers // Response headers (object)
vx.response.responseTime // Time in ms
vx.response.responseSize // Size in bytes
vx.response.text() // Raw response body (string)
vx.response.json() // Parsed JSON body (object)
Response Assertions (Chainable)
// Status assertion
vx.response.to.have.status(200);
// Header assertions
vx.response.to.have.header('Content-Type');
vx.response.to.have.header('Content-Type', 'application/json');
// Body assertions (dot-path)
vx.response.to.have.jsonBody('data.id');
vx.response.to.have.jsonBody('data.name', 'John');
Cluster Variables
// Set a variable (persisted to the cluster)
vx.clusterVariables.set('userId', body.data.id);
// Get a variable
const token = vx.clusterVariables.get('api_token');
// Remove a variable
vx.clusterVariables.unset('temp_value');
// Alias — vx.variables works the same way
vx.variables.set('key', 'value');
vx.variables.get('key');
Test Runner
vx.test('Status is 200', () => {
vx.expect(vx.response.code).toBe(200);
});
vx.test('Has user data', () => {
const body = vx.response.json();
vx.expect(body.data).toBeDefined();
vx.expect(body.data.name).toBeType('string');
});
Each vx.test() block is tracked as pass/fail. Results appear in the Tests tab of the Response Viewer.
Expect Chain (Full Reference)
The vx.expect(value) function returns a chainable assertion object:
| Assertion | Description |
|---|---|
.toBe(expected) | Strict equality (===) |
.toEqual(expected) | Same as .toBe() |
.toBeDefined() | Value is not undefined |
.toBeType(type) | Checks typeof (e.g., 'string', 'number', 'object') |
.to.be.a(type) | Same as .toBeType() |
.to.equal(expected) | Strict equality |
.to.include(value) | String includes or array contains |
.to.have.property(key) | Object has the given key |
.to.not.* | Negates any assertion (e.g., .to.not.be.undefined) |
Postman Compatibility
VortexHQ provides a pm alias for seamless migration from Postman:
// These work identically to their vx counterparts
pm.response.code;
pm.response.json();
pm.collectionVariables.set('key', 'value');
pm.collectionVariables.get('key');
pm.test('name', fn);
pm.expect(value).to.equal(expected);
When importing a Postman collection, all pm.* calls in scripts are automatically converted to vx.* equivalents.
Console Output
Use console.log() in scripts — output appears in the response console panel. Useful for debugging variable values and response data.
Script Execution
Scripts are executed in a sandboxed environment via new Function(). The vx (and pm) objects, console, and setTimeout/setInterval are available as globals. Scripts have access to the current request’s resolved variables.