JavaScript API Reference
The JavaScript test step runs scripts in the Google V8 engine and exposes three sandbox objects — aethrix, pm, and insomnia. This page documents the complete API surface of each, as implemented in the runtime.
- aethrix (Native)
- pm (Postman)
- insomnia (Insomnia)
aethrix — Native Aethrix API
The primary API for writing assertions and accessing test context. Prefer this for all new scripts.
aethrix.request
Information about the preceding Send Request step.
| Property | Type | Description |
|---|---|---|
url | string | null | The request URL |
method | string | The HTTP method (e.g. GET, POST); empty when unavailable |
aethrix.response
The response from the preceding Send Request step.
| Property / Method | Returns | Description |
|---|---|---|
code | number | HTTP status code (0 if no response) |
status | string | HTTP reason phrase |
ok | boolean | true if status is 2xx |
body | string | Raw response body |
text() | string | Raw response body |
json() | object | null | Parsed JSON body (via JSON.parse) |
headers() | object | Response headers as a key/value dictionary |
aethrix.assert.*
Response-targeted and general-purpose assertion methods. All throw an exception on failure, caught by aethrix.check().
assertFor(step)
Creates an assertion helper bound to a specific Send Request step's response instead of the automatically-found preceding step. Useful when the script targets a step that isn't the immediate predecessor.
var sendStep = testStep.findSendStepByName("Get user");
var assert = aethrix.assertFor(sendStep);
assert.statusCode(200);
assert.jsonPath("$.data.name");
testStep.findSendStepByName(name, testCaseName?, testSuiteName?) searches the current test case for a Send Request step by name; pass testCaseName and/or testSuiteName to search another test case or an entire suite.
Response Assertions
| Method | Parameters | Description |
|---|---|---|
statusCode(code) | code: number | string | Check HTTP status. Exact: 200, 404. Range: "2xx", "4xx", "5xx" |
header(name) | name: string | Check a response header exists |
header(name, value) | name: string, value: string | Check a response header equals a value |
header(name, value, cm) | name: string, value: string, cm: string | Check with compare mode |
jsonPath(path) | path: string | Check a JSON path exists in the response body |
jsonPath(path, expected) | path: string, expected: any | Check a JSON path equals a value |
jsonPath(path, expected, cm) | path: string, expected: any, cm: string | Check with compare mode |
bodyContains(text) | text: string | Check the response body contains text |
bodyContains(text, cm) | text: string, cm: string | Check with compare mode |
General Assertions
| Method | Parameters | Description |
|---|---|---|
equal(actual, expected) | actual: any, expected: any | Check two values are equal |
equal(actual, expected, cm) | actual: any, expected: any, cm: string | Check with compare mode |
contains(text, substring) | text: string, substring: string | Check text contains a substring |
contains(text, substring, cm) | text: string, substring: string, cm: string | Check with compare mode |
Compare Modes (cm)
| Value | Behavior |
|---|---|
"binary" (default) | Case-sensitive, exact comparison |
"caseinsensitive" | Case-insensitive and accent-insensitive |
"loose" | Case-insensitive, ignores whitespace, letters/digits/symbols only |
"regex" | Regular expression match, case-sensitive |
"regexignorecase" | Regular expression match, case-insensitive |
aethrix.assert.not.*
All assertion methods are also available negated via .not:
aethrix.assert.not.statusCode(500);
aethrix.assert.not.header("X-Error");
aethrix.assert.not.jsonPath("$.error");
aethrix.assert.not.bodyContains("error");
aethrix.assert.not.equal(actual, "bad value");
aethrix.assert.not.contains(text, "forbidden");
not supports statusCode, header, jsonPath, bodyContains, equal, and contains.
aethrix.check(name, fn)
Groups assertions into a named check. Failures are reported with the check name.
aethrix.check("Response validation", () => {
aethrix.assert.statusCode(200);
aethrix.assert.jsonPath("$.data.token");
});
Passes appear as ✓ Response validation in diagnostics; failures as ✗ Response validation: reason.
aethrix.variables
Read/write Aethrix test variables across scopes.
| Method | Description |
|---|---|
get(name): string | null | Read a variable (searches local → test case → suite → project) |
set(name, value) | Write a variable to the step's local scope |
has(name): boolean | Check if a variable exists in any scope |
var userId = aethrix.variables.get("UserId");
aethrix.variables.set("generatedEmail", "test@example.com");
if (aethrix.variables.has("token")) { /* ... */ }
aethrix.environment
Read/write the project's current test environment variables.
| Method | Description |
|---|---|
get(name): string | null | Read an environment variable |
set(name, value) | Write an environment variable |
has(name): boolean | Check if an environment variable exists |
aethrix Diagnostics
| Method / Property | Description |
|---|---|
info(message) | Add a diagnostic message to the test report |
warn(message) | Add a [WARN]-prefixed diagnostic message |
progress (get/set) | Script progress indicator, clamped to 0.0–1.0 |
aethrix.info("Processing items...");
aethrix.warn("Unexpected empty list");
aethrix.progress = 0.75;
pm — Postman Compatibility API
A minimal Postman-compatible API surface for running imported Postman test scripts verbatim. This is a compatibility layer — prefer aethrix.* for new scripts.
pm.test(name, fn)
Runs a function as a named test. If the function throws, the test is marked failed.
pm.test("Status code is 200", () => {
pm.expect(pm.response.code).to.equal(200);
});
pm.expect(value)
Returns a chainable PmExpect assertion builder. Throws on failure (caught by pm.test()).
Chain Properties (identity — return this)
| Property | Description |
|---|---|
to | Identity |
be | Identity |
and | Identity |
Assertion Methods
| Method | Description |
|---|---|
equal(expected) | String equality comparison |
eql(expected) | Alias for equal |
include(substring) | Check value contains substring |
a(type) | Type check: "string", "number", "null", "object" |
above(n) | Numeric: value > n |
below(n) | Numeric: value < n |
oneOf(values) | Check value is in an array |
Negation
| Property | Returns | Description |
|---|---|---|
not | PmExpectNot | Negated chain with equal and include |
pm.expect(200).not.to.equal(404);
pm.expect("hello").not.to.include("error");
pm.response
Response from the preceding Send Request step.
| Property / Method | Returns | Description |
|---|---|---|
code | number | HTTP status code |
status | string | HTTP reason phrase |
ok | boolean | true if 2xx |
text() | string | Raw response body |
json() | object | null | Parsed JSON body |
to.have.status(code) | boolean | Check status code |
to.have.header(name) | boolean | Check header exists |
pm.environment
Read/write environment variables with get/set/has/unset. Mutations are flushed back to the Aethrix environment after script execution.
pm.environment.set("token", responseJson.token);
var baseUrl = pm.environment.get("BaseUrl");
pm.environment.unset("temp");
pm.globals
Read/write global variables (mapped to Aethrix test parameters).
pm.globals.set("runCount", "1");
var count = pm.globals.get("runCount");
pm.globals.unset("runCount");
pm.variables
Read-only access to test parameters.
var param = pm.variables.get("paramName");
var exists = pm.variables.has("paramName");
Supported vs Unsupported Postman API
| Postman API | Status |
|---|---|
pm.test(), pm.expect() | Supported |
pm.response.* | Supported (subset) |
pm.environment.* | Supported (incl. unset) |
pm.globals.* | Supported (incl. unset) |
pm.variables.* | Supported (read-only) |
pm.request.* | Not supported |
pm.collectionVariables.* | Mapped to pm.environment |
pm.sendRequest() | Not supported |
pm.info, pm.cookies | Not supported |
pm.visualizer | Not supported |
insomnia — Insomnia Compatibility API
A minimal Insomnia-compatible API surface for running imported Insomnia test scripts verbatim. This is a compatibility layer — prefer aethrix.* for new scripts.
insomnia.response
Response from the preceding Send Request step.
| Property / Method | Returns | Description |
|---|---|---|
code | number | HTTP status code |
status | string | HTTP reason phrase |
text() | string | Raw response body |
json() | object | null | Parsed JSON body |
headers() | object | Response headers as key/value dictionary |
var body = insomnia.response.text();
var json = insomnia.response.json();
var code = insomnia.response.code;
var contentType = insomnia.response.headers()["Content-Type"];
insomnia.environment
Read/write environment variables directly to the Aethrix test environment.
| Method | Description |
|---|---|
get(name) | Read an environment variable |
set(name, value) | Write an environment variable |
has(name) | Check if an environment variable exists |
insomnia.environment.set("authToken", json.access_token);
var url = insomnia.environment.get("baseUrl");
Supported vs Unsupported Insomnia API
| Insomnia API | Status |
|---|---|
insomnia.response.* | Supported (subset) |
insomnia.environment.* | Supported |
insomnia.request.* | Not supported |
insomnia.test() | Not supported (use pm.test() or aethrix.check()) |
insomnia.expect() | Not supported (use aethrix.assert.*) |
insomnia.sendRequest() | Not supported |
insomnia.globals | Not supported |
insomnia.collectionVariables | Not supported |
Other exposed globals
In addition to aethrix, pm, and insomnia, the script engine also exposes:
| Global | Description |
|---|---|
testParameters | The test parameters collection for the run |
testStep | The current JavaScript test step object — provides findSendStepByName(name, testCaseName?, testSuiteName?) |
project | The containing automation project (when available) |
host | ClearScript host functions |
console | Postman-style console.log/info/warn/error routed to step diagnostics |
Console | The .NET Console type for debugging output |
Execution Pass/Fail
After the script runs, the step result is determined by this logic (following the "no error = pass" convention):
| Priority | Condition | Result |
|---|---|---|
| 1 | Any pm.test() executed and at least one failed | Failure |
| 2 | Any aethrix.check() executed and at least one failed | Failure |
| 3 | Script returns true | Success |
| 4 | Script returns "OK" | Success |
| 5 | All pm.test() executed passed (and at least one ran) | Success |
| 6 | All aethrix.check() executed passed (and at least one ran) | Success |
| 7 | Script returns false (and no assertions ran) | Failure |
| 8 | None of the above (e.g. no assertions, no recognized return) | Success |
If both Postman and Aethrix assertions are used in the same script, a failure in either framework fails the step. Thrown exceptions (including syntax errors) fail the step and report the error location.