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 for semantic_similarity comparison assertions:
    • lenient - the default. Applied automatically if sensitivity is omitted for semantic_similarity comparison assertions.
    • moderate - a tighter similarity threshold.
    • strict - the tightest similarity threshold.

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_status

    Assert on the value of the HTTP status code from the Response.

  • response_headers

    Assert on the value of a Response Header. You must include a Property with the header name to assert on.

  • response_json

    Parse the response body as JSON. You must include a Property with the JSON path to assert on.

  • response_xml

    Parse the response body as XML. You must include a Property with the XPath to assert on.

  • response_text

    Parse the response body as plain text. This source does not specify a Property.

  • response_time

    Assert on the execution time of the response in milliseconds.

  • response_size

    Assert on the size of the Response body in bytes.

Assertion comparisons list

Comparisons

  • equal

    A string equality check on the given property and value.

  • empty

    The given value is an empty string.

  • not_empty

    The given value is not an empty string.

  • not_equal

    The given string property is not equal to the given string value.

  • contains

    The given string value is found in the given property.

  • does_not_contain

    The given string value is not found in the given property.

  • is_a_number

    The source property can be converted to a numeric value. This comparison does not take a value.

  • equal_number

    The source property is numerically equal to the given value. This comparison ensures the values are able to be converted to numbers.

  • is_less_than

    The given property is numerically less than the given value.

  • is_less_than_or_equal

    The given property is numerically less than or equal to the given value.

  • is_greater_than

    The given property is numerically greater than the given value.

  • is_greater_than_or_equal

    The given property is numerically greater than or equal to the given value.

  • has_key

    The JSON property evaluates to an object and contains the given value as a key. Source must be response_json.

  • has_value

    The JSON property evaluates to an array and contains the given value as an element. Source must be response_json.

  • is_null

    The JSON property has a NULL value. Source must be response_json.

  • semantic_similarity 

    The 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
	}
}