Assertions
Once a response has been returned from the request, assertions are evaluated against the JSON response body to verify expected values.
The assertion is written as a list item (ordered or unordered list) in the following syntax:
* `$.json.path` operator `expected_value`- Selector: a JSON path starting with
$. See Selectors. - Operator: comparison or regex operator. See Assertion Operators.
- Expected value: number, string (quoted), regex (
/pattern/),null, orundefined.
Assertion Operators
Note: Unary operators like “is defined”/”is undefined” are not supported. Use comparisons with
undefined/nullas shown below.
== (Equal)
== is an operator to check if the value is equal to the expected value.
Value types for this assertion can be a number, string, or regular expression.
Example
* `$.status` == `"ok"`
* `$.data.id` == `42`!= (Not Equal)
!= is an operator to check if the value is different from the expected value.
Value types for this assertion can be a number, string, or regular expression.
Example
* `$.data.name` != `"Guest"`> (Greater Than)
> is an operator to check if the value is greater than the expected value.
Value types for this assertion must be a number.
Example
* `$.metrics.duration_ms` > `0`>= (Greater Than or Equal To)
>= is an operator to check if the value is greater than or equal to the expected value.
Value types for this assertion must be a number.
Example
* `$.metrics.duration_ms` >= `100`< (Less Than)
< is an operator to check if the value is less than the expected value.
Value types for this assertion must be a number.
Example
* `$.data.count` < `30`<= (Less Than or Equal To)
<= is an operator to check if the value is less than or equal to the expected value.
Value types for this assertion must be a number.
Example
* `$.data.count` <= `30`=~ (Regex Match)
=~ is an operator to check if the value matches the regex pattern.
The pattern is enclosed between forward slashes like /pattern/.
Example
* `$.title` =~ `/^Executive/`
* `$.department` =~ `/[A-Z]{2,}/`!~ (Regex Not Match)
!~ is an operator to check if the value does not match the regex pattern.
Example
* `$.title` !~ `/^Sales/`Regular Expression Assertion
Regular expressions are used in regex match/not-match assertions and can also be used in equality/difference assertions. The pattern is delimited by forward slashes.
Regex assertions operate on string values. Convert numbers in your API if needed.
Checking existence:
* `$.data.error` == `undefined` # not present
* `$.data.deleted_at` == `null` # null or not present
* `$.data.name` != `undefined` # present