Syvizo

Validations



Validations are the checks for values that are acceptable in the testing. In API testing, you can setup validations for headers and fields in the response body that are returned as part of the response when you send API request.


This is helpful when you want to automate the verification process rather than manually checking for the fields for their values. This is very useful when you want to setup automated testing of a set of APIs. When you have setup validations, the test will be successful only when all the validations are met for the configured conditions and not only based on the response status returned.


The validations can be setup once and can be reused a number of times. These can be added to Test Sets to run as part of your full validation process for the API before deployment to higher environments and roll outs.


More information can be found in the section for “Test Sets”.


To setup validations, you can click on the "Validations" icon , which will open validations pane on the right side panel of screen. The upper part of the screen is same as the one in Test APIs, and lower part of the screen is the validation setup screen. 


Validations



Since the validations are based on the response, you can setup the request with its required parts as you do when you test an API and click on “Fetch Response” in the validation pane. This action will get the response structure based on which the validations can be set up.



Header Validations

To set validations for header values, click on add in the “Header Validations” section. This will open a dialog box. You can select the header for which validation needs to be added. If you do not find the header you are looking for, you can select “other” in the drop down menu and enter the name of the header in the given text box. Select the operator from the “Operator” drop down. This operator is used to compare the value of the header from response. 


The available operators are as below they compare the value of the header from the response with the value specified in the validation value text box:

  • = checks if the value of header is equal to the validation value specified
  • < checks if the value of header in response is is smaller than the validation value
  • <= checks if the value of header in response is is smaller than or equal to the validation value
  • > checks if the value of header in response is larger than the validation value
  • >= checks if the value of header in response is larger than or equal to the validation value
  • != checks if the value of header is not equal to the validation value(invalid if the values are equal)
  • startsWith (string) checks if the returned value of header starts with validation value
  • endsWith (string) checks if the returned value of header ends with validation value
  • Contains (string) checks if the returned value of header contains validation value
  • length(string) < checks if the length of returned value of header is less than validation value
  • length(string) > checks if the length of returned value of header is larger than validation value
  • present checks if the response has the header (presence of header, irrespective of value)
  • Value in checks if the header value returned in the response is one of the values specified in the validation values separated by comma
  • not present checks if header is not present (presence of header will make it invalid)
  • has child checks if the value of header has any child element

     

All the configured validations are done at runtime and the test is considered successful or passed if none of them are invalid.



Body Validations

For the validation setup for the response body, click on the “Add” button in “Body Validations” section. The dialog box in this case shows the response json structure in the tree format. Select an element from the tree for which you want to add validations. Select the operator from the “Operator” drop down box and specify the validation value in the validation value text box.


Do note that selecting the element in tree picks the json path of the field which in a way is qualified name of the field. In case response has more than one fields with same name at different location in the structure, the validation will be performed only for the field with selected json path (location in the structure).


The available operators are as below they compare the value of the selected field from the response with the value specified in the validation value text box:

  • = checks if the value of the field is equal to the validation value specified
  • < checks if the value of the field in response is is smaller than the validation value
  • <= checks if the value of the field in response is is smaller than or equal to the validation value
  • > checks if the value of the field in response is larger than the validation value
  • >= checks if the value of the field in response is larger than or equal to the validation value
  • != checks if the value of the field is not equal to the validation value(invalid if the values are equal)
  • startsWith (string) checks if the returned value of the field starts with validation value
  • endsWith (string) checks if the returned value of the field ends with validation value
  • Contains (string) checks if the returned value of the field contains validation value
  • length(string) < checks if the length of returned value of the field is less than validation value
  • length(string) > checks if the length of returned value of the field is larger than validation value
  • present checks if the response has the the field (presence of the field, irrespective of value)
  • Value in checks if the the field value returned in the response is one of the values specified in the validation values separated by comma
  • not present checks if the field is not present (presence of the field will make it invalid)
  • has child checks if the value of the field has any child element


Validations use environment variables from the active environment.