Validation Scripts
This topic presents a variety of CloudTest validation scripts. Scripts can be copied and pasted directly into the CloudTest Script Editor using Central > Scripts. Longer scripts have an accompanying image that can be clicked to pop out the full example script. Shorter scripts are presented inline (in the right column). | |
Validation Scripts
This example will throw an error if the specified text does not appear in the prior response. |
![]() |
First, get the Message that precedes this Script. |
var msg = $context.currentItem.previousItem; |
Then, get the response fromthe
HTTP_BODY
. If there was no response, output an informational message as such. |
var response = msg.getResponse(msg.RESPONSE_HTTP_BODY);
if (response == null)
$context.result.postMessage($context.result.LEVEL_INFO, "Message " + msg.name + " received no response to validate.");
else |
Then, specify the string to find. |
var stringToFind = "Account Information"; |
Check for the value in the response. If it doesn't exist, output an error. |
var searchIndex = response.indexOf(stringToFind);
if (searchIndex == -1)
{
var details = "Response:\n" + response + "\n\nValue searched for:\n" + stringToFind;
$context.result.postMessage($context.result.LEVEL_ERROR, "Expected value not found in response to Message " + msg.name, details);
}
}
msg.clearResponse(); |
|
![]() |
First, get the Message that precedes this Script. |
var msg = $context.currentItem.previousItem; |
Then, get the response from the
HTTP_BODY
. If there was no response, output an informational message as such. |
var response = msg.getResponse(msg.RESPONSE_HTTP_BODY);
if (response == null)
$context.result.postMessage($context.result.LEVEL_INFO, "Message " + msg.name + " received no response to validate.");
else |
Then, specify the string to find. |
var stringToFind = "seeing this error because you have"; |
Check for the value in the response. If the value does exist in the response, output an error. |
if (searchIndex > -1)
{
var details = "Response:\n" + response + "\n\nValue searched for:\n" + stringToFind;
$context.result.postMessage($context.result.LEVEL_ERROR, "Error found in response to Message " + msg.name, details);
}
}
msg.clearResponse(); |
|
![]() |