Skip to content

Response Assertion

Response Assertion Post Processors lets you check at runtime the HTTP responses satisfy conditions, e.g.:

  • The response body must contain some text,
  • A response header must have a certain value,
  • The response code must be 200.

Assertions can be graphed in bench reports.

Response Assertion

The first line displays the response assertion name. This field is optional. The second line contains tab headers to access:

  • Simple Configuration, to easily generate an assertion,
  • Advanced Configuration, for more specific needs

The check button, on the right of the action, lets you validate the assertion against the selected HTTP response:

  • Green: the assertion is valid for the selected response,
  • Orange: the assertion is invalid for the selected response.

Note

The response selector, on the right, lets you choose which HTTP response is used for configuring and checking the Response Assertion. So if neither recorded responses nor Validate VU responses are available, you have to configure the Response Assertion blindly.

Simple configuration

response-assertion

Node

The simple mode is only available for 'Body', 'Header' and 'Status Code' fields.

Body assertion

Response Assertion body

The following procedure explains how to simply configure an assertion on a HTTP response body:

  1. Select the Configuration tab,
  2. Select Body on the right toggle buttons,
  3. Browse the response body, and select the text that must be present for each HTTP repsonse.

Header assertion

Response Assertion header

The following procedure explains how to simply configure an assertion on HTTP response headers:

  1. Select the Configuration tab,
  2. Select Headers on the right toggle buttons,
  3. Select the header in the table, its value must be the same in every HTTP response.

Status code assertion

Response Assertion code

The following procedure explains how to simply configure an assertion on a HTTP response status:

  1. Select the Configuration tab,
  2. Select Status code on the right toggle buttons,
  3. The recorded status code is displayed on tp of the panel,
  4. Select the status code in the selector, its value must be the same for every HTTP response.

Advanced configuration

Response Assertion advanced

You may start by using the simple mode, and then switch to advanced to customise the generated configuration.

The Advanced tab may fulfil more complex requirements.

The following procedure explains how to configure an assertion on a HTTP response:

  1. Select the Advanced tab,
  2. Select the response field to assert: Headers, Body or Status code on the right toggle buttons,
  3. Select the Apply to value, the request with or without its sub-requests,
  4. Select the Pattern matching rule,
  5. Select whether to negate the patterns,
  6. Select the Operator,
  7. Select Assume success,
  8. Type in one or more patterns in the bottom table.

Warning

The Apply to is only relevant if the parent HTTP Request action has the Download resources? option enabled. Otherwise there will not be any sub-request.

Note

The patterns depend on the Pattern matching rule:

  • Contains: the patterns are only simple strings that must be present anywhere in the response part,
  • Matches: the patterns are regular expressions that must match the response part,
  • Equals: the patterns strings that must be the same as the whole response part (only relevant with the Status Code).

Ignore response code

Another use of response assertions is to ignore certain HTTP response codes. This can be useful when your application is using custom codes that are not part of the list of standard codes.

The most optimized way is to configure it like this: Response Assertion assume success

Selecting the Status Code only option makes it much more efficient resource wise.

And if you want to apply it to all requests, you can place it at the root level of your script:

Response Assertion assume success root

This way every response will be checked against it.

Warning

When running a validation, we will also compare the response code to the recorded request. Because of this the status of the response may still be orange.