Skip to main content

How to validate a response?

You can construct the URL of the endpoint using JavaScript string concatenation expressions that can include variables. So for example in the following snippet the variable $clientNumber is used in that path of the URL of a post call:

var $response = post($url, $payload );
var $jsonList = JSON.parse($response.getDataString());
if ($jsonList.isSuccess !== "true") {
   throw "Call was not successful. Message: "+$jsonList.message;
}

Optionally you can also use assert calls like:

var $response = post($url, $payload );
var $jsonList = JSON.parse($response.getDataString());
assertEquals($jsonList.isSuccess,"true");

You can also check other response information like status code

assertEquals($response.status, 200);

We can also use the same approach even if the response code is seen in header as well

assertEquals($response.status, 200);

Last updated: March 21, 2023

If you have any feedback on this topic, please contact us at documentation@appvance.ai