跳到主要内容

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 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.

PropertyTypeDescription
urlstring | nullThe request URL
methodstringThe HTTP method (e.g. GET, POST); empty when unavailable

aethrix.response​

The response from the preceding Send Request step.

Property / MethodReturnsDescription
codenumberHTTP status code (0 if no response)
statusstringHTTP reason phrase
okbooleantrue if status is 2xx
bodystringRaw response body
text()stringRaw response body
json()object | nullParsed JSON body (via JSON.parse)
headers()objectResponse 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​

MethodParametersDescription
statusCode(code)code: number | stringCheck HTTP status. Exact: 200, 404. Range: "2xx", "4xx", "5xx"
header(name)name: stringCheck a response header exists
header(name, value)name: string, value: stringCheck a response header equals a value
header(name, value, cm)name: string, value: string, cm: stringCheck with compare mode
jsonPath(path)path: stringCheck a JSON path exists in the response body
jsonPath(path, expected)path: string, expected: anyCheck a JSON path equals a value
jsonPath(path, expected, cm)path: string, expected: any, cm: stringCheck with compare mode
bodyContains(text)text: stringCheck the response body contains text
bodyContains(text, cm)text: string, cm: stringCheck with compare mode

General Assertions​

MethodParametersDescription
equal(actual, expected)actual: any, expected: anyCheck two values are equal
equal(actual, expected, cm)actual: any, expected: any, cm: stringCheck with compare mode
contains(text, substring)text: string, substring: stringCheck text contains a substring
contains(text, substring, cm)text: string, substring: string, cm: stringCheck with compare mode

Compare Modes (cm)​

ValueBehavior
"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.

MethodDescription
get(name): string | nullRead a variable (searches local → test case → suite → project)
set(name, value)Write a variable to the step's local scope
has(name): booleanCheck 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.

MethodDescription
get(name): string | nullRead an environment variable
set(name, value)Write an environment variable
has(name): booleanCheck if an environment variable exists

aethrix Diagnostics​

Method / PropertyDescription
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;

Other exposed globals​

In addition to aethrix, pm, and insomnia, the script engine also exposes:

GlobalDescription
testParametersThe test parameters collection for the run
testStepThe current JavaScript test step object — provides findSendStepByName(name, testCaseName?, testSuiteName?)
projectThe containing automation project (when available)
hostClearScript host functions
consolePostman-style console.log/info/warn/error routed to step diagnostics
ConsoleThe .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):

PriorityConditionResult
1Any pm.test() executed and at least one failedFailure
2Any aethrix.check() executed and at least one failedFailure
3Script returns trueSuccess
4Script returns "OK"Success
5All pm.test() executed passed (and at least one ran)Success
6All aethrix.check() executed passed (and at least one ran)Success
7Script returns false (and no assertions ran)Failure
8None 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.

See Also​