...
Scenario 4: Ignore whole response and check only the status code
This special variable is also helpful in ignoring whole test case response. Now, you can write your expected body like this:
Code Block | ||||
---|---|---|---|---|
| ||||
"{{*}}" |
vREST will simply replace the whole expected body with the actual response received before response validation and validator will only check the status code of API response.
Excerpt | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||
vREST supports a special variable "{{ Lets understand the concept of this variable by taking an example: Suppose we have an API which creates resource on server and returns the following JSON response:
Here "id" and "created_at" are dynamic fields, which we do not know the values in advance. Now question comes, how we can test these type of responses. There are various approaches to this problem.
If we do not want to take hassle on creating our own custom validator and we don't want to rely on only schema validation and we are ok with ignoring the dynamic properties of the test case, then this variable can be very helpful in handling such scenarios. Scenario 1: Ignore some of the JSON values while response validationIf you want to ignore some JSON values while response validation then you can specify this special variable against those JSON keys in the expected body for a test case. vREST simply replaces this special variable with the actual values received while test case execution in the expected body before sending the expected body to the validator for response validation. So, we can write our expected body like this:
vREST will simply replace this special variable with the actual values received before response validation. You can simply use the built-in "Default Validator" for the test case and you don't need to define any custom validator for the test case. Scenario 2: Partial Response ValidationThis special variable is also helpful in verifying partial JSON response. Suppose, in the above response, you want to validate only the resource_name and resource_url properties in the response, then you can write your expected body like this:
vREST will simply replace the other properties except "resouce_name" and "resource_url" in expected body from the actual response received before response validation. Note: Please use this variable with caution because later on if you add a new JSON key to the response, that new JSON key will also get ignored and your test case will always pass. Scenario 3: Ignore nested objects in the responseThis special variable is also helpful in ignoring nested objects. Suppose, in the above response, you want to ignore the whole "meta" object, then you can write your expected body like this:
vREST will simply replace the whole meta object and id property in expected body from the actual response received before response validation. |