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

Defining Assertion for Status Code
Sample POST Body (JSON) for Status Code = 200

"assertions": [
    {
        "source": "response_status", 
        "comparison": "equal_number", 
        "value": 200
    }
]

Defining 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"
    }
]

Defining Assertions for Response Time
Sample POST Body (JSON) for Response Time is faster than 1 second.

"assertions": [
    {
        "source": "response_time", 
        "comparison": "is_less_than", 
        "value": 1000
    }
]

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