In this section, response validators can be defined. Default response validators are already provided for reference. A custom response validator can be created by clicking on "New Validator" link in left hand side.
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.
A response validator function will get the following input parameters:
testcaseFirst parameter is test case, having all the details of a test case which has been provided in the test cases tab.
responseSecond 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
methodsThird 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.
Fourth parameter is variables map object. This parameter is a JSON object where key is the variable name and value is the variable's value.
- Note: You may directly change the variable's value in response validator. Please be cautious while changing variable's value in response validator because it may affect the subsequent test cases.