Payload Validations
How to Validate API Payloads with ContextQA
Validating API payloads ensures your APIs are returning the correct data. ContextQA makes this process straightforward, helping you check if fields like email match expectations in your test runs. Follow these steps to add and test payload validation in your API test case.
Open your API test case and locate the Validation section.
In the validation area, find the field for the JSON path. You’ll use this to point directly to the value you want to check. For example, if your result is stored under a variable called `result`, start your path with `result.`
To confirm the exact JSON path, navigate to the Run History, open the Response Body, and look for the field you want to validate, like `email`.
Copy the full JSON path to the email field, then return to your test case and paste that path into the JSON path field in the validation section.
Set the expected value for the validation. Choose Equals, select the string type if you’re validating an email, and enter the expected email address.
Click Create Update to save your validation rule.
Run the test case. Once it completes, check the results to see if the test passes or fails based on your payload validation.
If the actual response matches the expected email, the test passes. Otherwise, you’ll see failed results, which help you quickly spot issues.
To see a failing validation in action, try updating your expected value (for example, by removing a character from the email). Save and rerun the test case.
Review failed test case details in the Run History. Compare the expected and actual results to diagnose the mismatch.
Validating payloads with ContextQA helps you catch errors early and ensure your API responses match your requirements. Use this feature to add strong checks to your workflows and keep your API quality high.
Last updated