Configure assertions#

Assertions are used to check a request, response, or URL for compliance with specified conditions, for example, the presence of the string in the response.

If at least one of the Assertions conditions isn’t met, the request is considered erroneous.

You can check the Assertions results in Grafana dashboard.

Configure Assertions for an HTTP request#

  1. Open the test.

  2. Go to the group or click edit_button.

  3. Click edit_button for the required HTTP request and go to the Assertions tab:

    ../_images/um_assertions.en.png
  4. Select the scope:

    • Request body.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire body of the request matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the request body doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the request body doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the request body contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire request body fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the request body doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire request body doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the request body contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the request body contains the name parameter:

      ../_images/um_request_body_example.png
    • Request headers.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire request header matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the request header doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the request header doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the request header contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire request header fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the request header doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire request header doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the request header contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the Accept-Language header has the value en-US:

      ../_images/um_request_headers_example.png
    • Response body.

      Select the scope:

      • No filter. JSONPath and Xpath filters are not used:

        1. Select the type of condition:

          • Equals. The assertion is successful if the entire response body matches the specified string completely. Case-sensitive.

          • Not equals. The assertion is successful if the response body doesn’t match the specified string. Case-sensitive.

          • Not substring. The assertion is successful if the request body doesn’t contain the specified string. Case-sensitive.

          • Regexp contains. The assertion is successful if the response body contains a string that matches the regular expression pattern.

          • Regexp matches. The assertion is successful if the entire response body fully matches the regular expression pattern.

          • Regexp not contains. The assertion is successful if the response body doesn’t contain a string that matches the regular expression pattern.

          • Regexp not matches. The assertion is successful if the entire response body doesn’t match the regular expression pattern.

          • Substring. The assertion is successful if the response body contains the specified string. Case-sensitive.

        2. Specify a string or regular expression.

        For example, let’s check that the response body contains the name parameter:

        ../_images/um_response_body_nofilter_example.png
      • JSONPath. JSONPath is a query language for JSON. For more information, see JSON path syntax in detail:

        1. Specify the JSONPath expression.

        2. Select the type of condition:

          • Equals. The assertion is successful if the entire response body matches the specified string completely. Case-sensitive.

          • Exists. The assertion is successful if the JSONpath exists.

          • Is not null. The assertion is successful if the value isn’t equal to null.

          • Is null. The assertion is successful if the value is equal to null.

          • Not equals. The assertion is successful if the response body doesn’t match the specified string. Case-sensitive.

          • Not exists. The assertion is successful if the JSONpath doesn’t exist.

          • Regexp matches. The assertion is successful if the entire response body fully matches the regular expression pattern.

          • Regexp not matches. The assertion is successful if the entire response body doesn’t match the regular expression pattern.

        3. Specify a string or regular expression.

        For example, let’s check that the price of the first phone in the response body is not null:

        ../_images/um_response_body_json_example.png
      • XPath. XPath is a query language for XML. For more information, see XPath Syntax:

        1. Select the type of condition:

          • Matches. The assertion is successful if the response body matches the XPath expression.

          • Matches. The assertion is successful if the response body matches the XPath expression.

        2. Specify the XPath expression.

        For example, let’s check the phone name in the response body with id=1:

        ../_images/um_response_body_xpath_example.png
    • Response body size.
      1. Select the type of condition.

      2. Specify the expected size of the response body in bytes. For example:

        ../_images/um_response_body_size_example.png
    • Response code.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire response code matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the response code doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the response code doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the response code contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire response code fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the response code doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire response code doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the response code contains the specified string. Case-sensitive.

      2. Specify a string or regular expression. For example:

        ../_images/um_response_code_example.png
    • Response code size.
      1. Select the type of condition.

      2. Specify the expected size of the response code in bytes. For example:

        ../_images/um_response_code_size_example.png
    • Response document. The text of the document returned by the web server. For a list of supported document formats, see Apache Tika Supported Document Formats.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire document text matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the document text doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the document text doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the document text contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire document text fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the document text doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire document text doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the document text contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the document contains the string <html>:

      ../_images/um_response_document_example.png
    • Response duration.
      1. Select the type of condition.

      2. Specify the expected response time to the request in milliseconds.

      For example, let’s check that the response time doesn’t exceed 5 seconds:

      ../_images/um_response_duration_example.png
    • Response full size.
      1. Select the type of condition.

      2. Specify the expected size of the headers and the response body in bytes, for example:

        ../_images/um_response_full_size_example.png
    • Response headers.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire response header matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the response header doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the response header doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the response header contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire response header fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the response header doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire response header doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the response header contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the user-agent header doesn’t contain the standard value user-agent: Mozilla/5.0:

      ../_images/um_response_headers_example.png
    • Response headers size.
      1. Select the type of condition.

      2. Specify the expected size of the response headers in bytes. For example:

        ../_images/um_response_header_size_example.png
    • Response message.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire response message matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the response message doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the response message doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the response message contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire response message fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the response message doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire response message doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the response message contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the response message contains the Not found text:

      ../_images/um_response_message_example.png
    • Response message size.
      1. Select the type of condition.

      2. Specify the expected size of the response message in bytes. For example:

        ../_images/um_response_message_size_example.png
    • URL Sampled. It’s used to check that there was no redirect during the request execution, and the URL remained the same.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire URL matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the URL doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the URL doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the URL contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire URL fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the URL doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire URL doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the URL contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the URL is a link to a product in an online store:

      ../_images/um_url_sampled_example.png
  5. Click Save.

To delete an assertion, click delete_button.

Configure Assertions for an gRPC request#

  1. Open the test.

  2. Go to the group or click edit_button.

  3. Click edit_button for the required gRPC request and go to the Assertions tab:

    ../_images/um_grpc_assertions.en.png
  4. Select the scope:

    • Request body.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire body of the request matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the request body doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the request body doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the request body contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire request body fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the request body doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire request body doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the request body contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the request body contains the name parameter:

      ../_images/um_request_body_example.png
    • Request metadata.
      1. Select the type of condition:

        • Equals. The assertion is successful if all the request metadata matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the request metadata doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the request metadata doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the request metadata contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if all the request metadata fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the request metadata doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if all the request metadata doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the request metadata contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check the value of the request ID:

      ../_images/um_request_metadata_example.png
    • Response body.

      Select the scope:

      • No filter. JSONPath and Xpath filters are not used:

        1. Select the type of condition:

          • Equals. The assertion is successful if the entire response body matches the specified string completely. Case-sensitive.

          • Not equals. The assertion is successful if the response body doesn’t match the specified string. Case-sensitive.

          • Not substring. The assertion is successful if the request body doesn’t contain the specified string. Case-sensitive.

          • Regexp contains. The assertion is successful if the response body contains a string that matches the regular expression pattern.

          • Regexp matches. The assertion is successful if the entire response body fully matches the regular expression pattern.

          • Regexp not contains. The assertion is successful if the response body doesn’t contain a string that matches the regular expression pattern.

          • Regexp not matches. The assertion is successful if the entire response body doesn’t match the regular expression pattern.

          • Substring. The assertion is successful if the response body contains the specified string. Case-sensitive.

        2. Specify a string or regular expression.

        For example, let’s check that the response body contains the name parameter:

        ../_images/um_response_body_nofilter_example.png
      • JSONPath. JSONPath is a query language for JSON. For more information, see JSON path syntax in detail:

        1. Specify the JSONPath expression.

        2. Select the type of condition:

          • Equals. The assertion is successful if the entire response body matches the specified string completely. Case-sensitive.

          • Exists. The assertion is successful if the JSONpath exists.

          • Is not null. The assertion is successful if the value isn’t equal to null.

          • Is null. The assertion is successful if the value is equal to null.

          • Not equals. The assertion is successful if the response body doesn’t match the specified string. Case-sensitive.

          • Not exists. The assertion is successful if the JSONpath doesn’t exist.

          • Regexp matches. The assertion is successful if the entire response body fully matches the regular expression pattern.

          • Regexp not matches. The assertion is successful if the entire response body doesn’t match the regular expression pattern.

        3. Specify a string or regular expression.

        For example, let’s check that the price of the first phone in the response body is not null:

        ../_images/um_response_body_json_example.png
      • XPath. XPath is a query language for XML. For more information, see XPath Syntax:

        1. Select the type of condition:

          • Matches. The assertion is successful if the response body matches the XPath expression.

          • Matches. The assertion is successful if the response body matches the XPath expression.

        2. Specify the XPath expression.

        For example, let’s check the phone name in the response body with id=1:

        ../_images/um_response_body_xpath_example.png
    • Response body size.
      1. Select the type of condition.

      2. Specify the expected size of the response body in bytes. For example:

        ../_images/um_response_body_size_example.png
    • Response code.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire response code matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the response code doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the response code doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the response code contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire response code fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the response code doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire response code doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the response code contains the specified string. Case-sensitive.

      2. Specify a string or regular expression. For example:

        ../_images/um_response_code_example.png
    • Response code size.
      1. Select the type of condition.

      2. Specify the expected size of the response code in bytes. For example:

        ../_images/um_response_code_size_example.png
    • Response document. The text of the document returned by the web server. For a list of supported document formats, see Apache Tika Supported Document Formats.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire document text matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the document text doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the document text doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the document text contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire document text fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the document text doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire document text doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the document text contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the document contains the string <html>:

      ../_images/um_response_document_example.png
    • Response duration.
      1. Select the type of condition.

      2. Specify the expected response time to the request in milliseconds.

      For example, let’s check that the response time doesn’t exceed 5 seconds:

      ../_images/um_response_duration_example.png
    • Response full size.
      1. Select the type of condition.

      2. Specify the expected size of the metadata and the response body in bytes. For example:

        ../_images/um_response_full_size_example.png
    • Response message.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire response message matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the response message doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the response message doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the response message contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire response message fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the response message doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire response message doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the response message contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the response message contains the Not found text:

      ../_images/um_response_message_example.png
    • Response message size.
      1. Select the type of condition.

      2. Specify the expected size of the response message in bytes. For example:

        ../_images/um_response_message_size_example.png
    • Response metadata.
      1. Select the type of condition:

        • Equals. The assertion is successful if all the response metadata matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the response metadata doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the response metadata doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the response metadata contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if all the response metadata fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the response metadata doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if all the response metadata doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the response metadata contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check the value of the request ID:

      ../_images/um_response_metadata_example.png
    • Response metadata size.
      1. Select the type of condition.

      2. Specify the expected size of the response metadata in bytes. For example:

        ../_images/um_response_metadata_size_example.png
    • URL Sampled. It’s used to check that there was no redirect during the request execution, and the URL remained the same.
      1. Select the type of condition:

        • Equals. The assertion is successful if the entire URL matches the specified string completely. Case-sensitive.

        • Not equals. The assertion is successful if the URL doesn’t match the specified string. Case-sensitive.

        • Not substring. The assertion is successful if the URL doesn’t contain the specified string. Case-sensitive.

        • Regexp contains. The assertion is successful if the URL contains a string that matches the regular expression pattern.

        • Regexp matches. The assertion is successful if the entire URL fully matches the regular expression pattern.

        • Regexp not contains. The assertion is successful if the URL doesn’t contain a string that matches the regular expression pattern.

        • Regexp not matches. The assertion is successful if the entire URL doesn’t match the regular expression pattern.

        • Substring. The assertion is successful if the URL contains the specified string. Case-sensitive.

      2. Specify a string or regular expression.

      For example, let’s check that the URL is a link to a product in an online store:

      ../_images/um_url_sampled_example.png
  5. Click Save.

To delete an assertion, click delete_button.

See also

Preview of the response#

For the convenience of configuring assertions, use the preview of the response:

  1. Select a data source, for example, HAR.

  2. Go to the required tabs: Headers, Body, Cookies:

    ../_images/um_preview_response.en.png