This topic presents a variety of CloudTest error
detection scripts. The Scripts below 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).
Script 1: Set all play counts = 1
Set play count for all messages in a clip to 1 (note that this ignores any messages that might have other repeats set on them).
// Enable all following items in the current Clip.
var nextItem = $context.currentItem.nextItem;
while (nextItem != null)
nextItem.setRepeat(nextItem.REPEAT_TIMING_SERIAL, nextItem.REPEAT_TYPE_COUNT_CONSTANT, 1, nextItem.REPEAT_DISTRIBUTION_CONSTANT, 0);
nextItem = nextItem.nextItem;
Script 2: Set play count for subsequent clip elements
to 0 if an error is detected If an error is
detected, set play count for all subsequent clip elements in
a clip to 0 (note this requires that all clip elements have
a play count set to 1 at the beginning of the clip if serial
clip repeats are used) – refer to prior script example for
Script 3: Set all play counts = 0 if “authid” is not
Script 4: Disable chain if value not found in
This script can be added to the typical validation script. "BulkChain 1" is the name of the chain. There are 2 chains in the test, and they are named BulkChain 1 and 2. The script can find them by name and set them to a specific value. 0 = it will not play.
Script 5: Check for ErrorRedirect response
This example script checks the body of a response for errors and throws the error and message associated with the error.
Script 6: Compare response to message property and take
different actions on result (enable ErrorHandling chain
if error occurs)
This script compares response data (in this case something from a message header) to data that has been previously entered into a message property. This structure of a script is useful for error handling. If the response matches, continue with the test. If the response doesn’t match the expected response, output an error or stop the test.
This approach for error handling is powerful because it doesn’t rely on hard-coded values in the script. Instead, the matching is done on variables placed in individual messages.
Script 7: Try/Catch Example
Use this example script to develop an example of try/catch logic.
var msg = $context.currentItem.previousItem;
authId = msg.getResponse(msg.RESPONSE_HTTP_BODY_AS_JSON, "//authid");
wasFound = true;
// If you wanted to be more robust, you might check the value of
// "e.toString()" to see if is whatever error is returned when the
// item is not found. This catch will catch all errors.
wasFound = false;
// Do something here (found).
// Do something else here (not found).