Define assertions
Assertions allow you to specify success criteria for a given request, Ghost Inspector, subtest, or condition step. Each assertion is defined by a source, property, comparison, and value.
Use a semantic assertion when you want to compare a JSON response property against expected text by meaning rather than exact match, with an explicit sensitivity preset.
Supported request fields
- source
required
See assertion sources list. - property
required
The JSON/XML path to extract the actual response value from. - comparison
required
The type of assertion this represents. See assertion comparisons list. - value
required
The expected text to compare the extracted response value against. - sensitivity
optional
Used only forsemantic_similaritycomparison assertions:- lenient - the default. Applied automatically if sensitivity is omitted for
semantic_similaritycomparison assertions. - moderate - a tighter similarity threshold.
- strict - the tightest similarity threshold.
- lenient - the default. Applied automatically if sensitivity is omitted for
Any other value is rejected with a 400 Bad Request error.
Define assertion for status code
Sample POST body (JSON) for status code = 200
"assertions": [
{
"source": "response_status",
"comparison": "equal_number",
"value": 200
}
]
Define assertion for element contains text
Sample POST body (JSON) for JSON element 'address' contains the text "avenue"
"assertions": [
{
"source": "response_json",
"property": "address",
"comparison": "contains",
"value": "avenue"
}
]
Define assertions for response time
Sample POST body (JSON) for response time faster than 1 second.
"assertions": [
{
"source": "response_time",
"comparison": "is_less_than",
"value": 1000
}
]
Define semantic assertion
Sample POST body (JSON) for semantic assertion that finds expressions that confirm a successful order.
"assertions": [
{
"source": "response_json",
"property": "message",
"comparison": "semantic_similarity",
"value": "Your order has been confirmed.",
"sensitivity": "lenient"
}
]
Assertion sources list
Sources
-
response_statusAssert on the value of the HTTP status code from the Response.
-
response_headersAssert on the value of a Response Header. You must include a Property with the header name to assert on.
-
response_jsonParse the response body as JSON. You must include a Property with the JSON path to assert on.
-
response_xmlParse the response body as XML. You must include a Property with the XPath to assert on.
-
response_textParse the response body as plain text. This source does not specify a Property.
-
response_timeAssert on the execution time of the response in milliseconds.
-
response_sizeAssert on the size of the Response body in bytes.
Assertion comparisons list
Comparisons
-
equalA string equality check on the given property and value.
-
emptyThe given value is an empty string.
-
not_emptyThe given value is not an empty string.
-
not_equalThe given string property is not equal to the given string value.
-
containsThe given string value is found in the given property.
-
does_not_containThe given string value is not found in the given property.
-
is_a_numberThe source property can be converted to a numeric value. This comparison does not take a value.
-
equal_numberThe source property is numerically equal to the given value. This comparison ensures the values are able to be converted to numbers.
-
is_less_thanThe given property is numerically less than the given value.
-
is_less_than_or_equalThe given property is numerically less than or equal to the given value.
-
is_greater_thanThe given property is numerically greater than the given value.
-
is_greater_than_or_equalThe given property is numerically greater than or equal to the given value.
-
has_keyThe JSON property evaluates to an object and contains the given value as a key. Source must be response_json.
-
has_valueThe JSON property evaluates to an array and contains the given value as an element. Source must be response_json.
-
is_nullThe JSON property has a NULL value. Source must be response_json.
-
semantic_similarityThe JSON property is similar in meaning to the value and not necessarily literally equal.
Semantic Similarity Assertion Response
A semantic_similarity assertion's result includes the same fields as any other assertion result, plus Response fields for the semantic_similarity sub-object:
- sensitivity - the sensitivity preset used for the semantic similarity assertion. Defaults to lenient if it was omitted when the assertion was defined.
- verdict - one of the following:
- SAME - texts are judged equivalent in meaning.
- DIFFERENT - texts are judged not equivalent in meaning.
- GREY_VALIDATED - an ambiguous case that a secondary check confirmed as a match.
- GREY_REJECTED - an ambiguous case that a secondary check rejected as a mismatch.
- bi_encoder_score - The primary similarity score represented as floating point number (0-1) or null if either the actual or expected text was too short (less than 10 characters).
- cross_encoder_score - The secondary/fallback similarity score represented as a floating point number (0-1) or null if not calculated. Only populated when the bi_encoder_score fell in the ambiguous ("grey zone") range and a secondary, more precise check was run.
- accuracy_warning - A boolean indicating if the similarity of the actual and expected text couldn't be calculated because one of them was too short (less than 10 characters)
The semantic_similarity response sub-object:
{
"result": "pass",
"source": "response_json",
"property": "message",
"comparison": "semantic_similarity",
"target_value": "Your order has been confirmed.",
"actual_value": "We received your order.",
"error": null,
"semantic_similarity": {
"sensitivity": "lenient",
"verdict": "SAME",
"bi_encoder_score": 0.91,
"cross_encoder_score": null,
"accuracy_warning": false
}
}