Assertions
Assertions validate API responses with powerful comparison operators. Failed assertions stop sequence execution and report detailed errors.
Basic Assertions
.norn
test sequence ValidateResponse
GET https://api.example.com/users/1
# Status checks
assert $1.status == 200
assert $1.status < 300
# Body value checks
assert $1.body.id == 1
assert $1.body.name == "Alice"
end sequence Comparison Operators
| Operator | Description | Example |
|---|---|---|
== | Equals | assert $1.status == 200 |
!= | Not equals | assert $1.body.count != 0 |
> | Greater than | assert $1.body.age > 18 |
>= | Greater or equal | assert $1.body.age >= 18 |
< | Less than | assert $1.body.count < 100 |
<= | Less or equal | assert $1.duration <= 5000 |
String Operators
.norn
assert $1.body.email contains "@"
assert $1.body.name startsWith "A"
assert $1.body.name endsWith "ice"
assert $1.body.email matches "[a-z]+@[a-z]+\.[a-z]+" Schema Assertions
Validate a response body against a JSON Schema file:
.norn
assert $1.body matchesSchema "./schemas/todo.schema.json" Existence Checks
.norn
# Property must exist
assert $1.body.id exists
# Property must NOT exist
assert $1.body.deletedAt !exists Type Assertions
.norn
assert $1.body.id isType number
assert $1.body.name isType string
assert $1.body.active isType boolean
assert $1.body.tags isType array
assert $1.body.metadata isType object
assert $1.body.deletedAt isType null Timing Assertions
.norn
# Response must be fast
assert $1.duration < 2000 Custom Failure Messages
Add a custom message after the pipe:
.norn
assert $1.status == 200 | "API returned error status"
assert $1.body.id exists | "User ID was not returned" Array Assertions
.norn
# Access array elements
assert $1.body.users[0].name == "Alice"
# Check array length
assert $1.body.users.length > 0