Types of Validators
vREST provides the following default response validators, and also provide you a way to define your own custom validator.
Default Validator validates the expected and actual responses (response body) for exact match. If the value doesn't match, it simply fails the test case. We need to define Expected Body for the test case, if we choose this. Any variables in expected body are first replaced and then provided to the validator for response validation.
Default Schema Validator validates the schema of actual response instead of checking for exact content match. We need to define Expected Schema for the test case, if we choose this. If we use this validator, then we don't need to define the Expected Body.
Custom Validator validates the actual response by your own way. Most of the cases of response validation can be handled with the above default validators. However, you may define your own custom validators for customized response validation.
Thus, you can add a custom response validator into your assertions. To create a custom response validator,
- Go to Configuration Tab >> Response Validators section
- Click on Add Response Validator button, to create the new response validator.
- Edit the validator code according to yourself.
- Give it a name and save it.
A response validator function will get the following input parameters:
First parameter is test case, having all the details of a test case which has been provided in the test cases tab.
Second parameter is actual response of the HTTP request. It is a JSON object with the following keys:
- headers: HTTP Response headers retrieved
- actualResults: HTTP Response result retrieved. It is also a JSON object with the following keys:
- content: (String) Actual HTTP Response body
- resultType: (String) Content type of HTTP Response body
Third parameter is methods object. This parameter is a JSON object where key is the utility method name and value is the utility method reference.
- So, you may write your own custom utility methods and use them in your custom response validators.