1. Home
  2. Docs
  3. Portal
  4. Assertions

Assertions

Assertions allow you to specify expected data in the response to a request made in an API run. On API run, the response is determined by whether or not all the assertions pass. If any assertion fails, the API fails. Assertions can be made against status code, response time/size, and JSON body.

Status Code

Users can set what is expected status code API response should return. For that select Status Code from the Source option list. Select which comparison you want to perform. For example here “equals” is selected. Add the value of the status code , which you are expecting after the API run.

After API run, the response is determined by whether or not all the assertions pass. If any assertion fails, the API fails. API showing the result as failed, because assertion was failed for status code 201.

In the response section, you can see which assertion has failed.

Response Size (bytes)

Users can determine API response result based on Response Size assertion. For that select Response Size from the Source option list. Select which comparison you want to perform. For example here “greater than” is selected. Add the value of the response size in bytes, which you are expecting after the API run.

In the response section, you can see which assertion has passed/failed.

Response Time (ms)

Users can determine API response result based on Response Time assertion. For that select Response Time from the Source option list. Select which comparison you want to perform. For example here “less than” is selected. Add the value of the response time in miliseconds, which you are expecting after the API run.

In response, you can see whether the assertion has passed or failed.

JSON Body

User need to specify the JSON body object expression to locate the data to extract.

Select JSON body from the Source option list. Select which comparison you want to perform. For example here “equals” is selected. Add JSON key name in Property box. and expected value in Target Value. You will get auto suggestions for the property names, after the first API run.

Sample JSON expression

Check below example to see how expression can be defined.

Example 1: Top-level property

Expression: lastName
Value: Doe

Example 2: Nested property

Expression: address.city
Value: New York

Example 3: Nested property within array

Expression: phoneNumbers[0].number
Value: 212-555-4321

Example 4: Nested property within last element of array

Expression: phoneNumbers[-1].number
Value: 123-555-4567

Was this article helpful to you? Yes No

How can we help?