Validating API Responses

Assertions are used to validate the response from the API and ensure that it meets the expected criteria. This section will guide you through the process of adding assertions to your API test cases.

  • Navigate to the Test Case:

  • Quick Test the API:

    • Click on 'Send' button to run the API call and wait for the response.

  • Open Assertions Section:

    • Once you have the API response. Click on the "Assertions" tab within the test case.

  • Define Assertion:

    • Select the assertion type from the dropdown (e.g., Received Response). To add assertion on response header. Select 'Received Headers' from the assertion type dropdown.

    • Choose the condition for the assertion (e.g., Equals, Contains, Greater Than).

    • Actual Value will be auto-captured from the received response. Enter the expected value for the assertion. You can also parameterise the actual value to validate the dynamic values.

    • Select the checkboxes to add assertions.

  • Review and Save:

    • Review all assertions for accuracy and completeness.

    • Click the "Save" button to finalise the test case.

  • View Assertions

    • To review the added assertions, navigate to 'View Assertions'.

    • History of all the added assertions would be captured in 'View Assertions' section. For example, if there are keys in response which dynamically appears in specific scenarios, you can view those added assertions in this section.

    • Delete Assertions: You can choose the added assertions and delete the assertions which are not required.

Example:

Here's an example of an assertion. It is important to add assertion on status code irrespective of positive or negative scenario, as it helps to identify immediately if the API fails.

  • Assertion Name: Status Code

  • Condition: Equals

  • Expected Value: 200

  • Actual Value: Value from the API response

Last updated