In this post, we will see, how we can use variables in XML request body to make mock server more useful for our needs. Mock server request body matching works in the same way as we compare response body by using Default Validator for vREST Test cases.
We will now cover various scenarios to match XML request body:
If we want to return some API mock response based on static XML request body then in that case, simply define the static XML request body in API Mock >> Request tab >> Raw Body sub tab.
Now, in the incoming mock request, if the request URL and method matches and request body of the incoming mock request matches exactly with the XML body specified in the above image then mock server will return the response specified in the response tab of this API mock.
Now, suppose in scenario 1, we don't want to compare the value of name and email value in the XML request body then we may write the raw body like this by using special variable __STAR_VAR__:
Now, suppose we want to validate the existence of name tag and want to compare the value of email tag and we want to ignore rest of the properties in the XML request body, then we may write the raw body like this:
Now suppose we want to extract the name and email property from the incoming mock request and we want to use these properties in constructing the response of our Mock API. First we will see, how we may extract values from incoming XML request body:
To extract the name and email property from the request XML body, simply declare them as variables in the XML request body as shown below.
Now, you may use these extracted variables in the API mock response like this: