Error Detection and Handling Scripts

Document created by DPM Admin on Jul 21, 2017
Version 1Show Document
  • View in full screen mode

This topic presents a variety of SOASTA CloudTest error detection scripts. The Scripts below can be copied and pasted directly into the SOASTA 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).



    1. 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 = nextItem.nextItem;

    1. 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 an example.

  1. Script 3: Set all play counts = 0 if “authid” is not returned

Set all play counts in clip = 0 if “authid” is not returned from the login POST.

  1. Script 4: Disable chain if value not found in response

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.

  1. 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.

  1. 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.

  1. Script 7: Try/Catch Example

Use this example script to develop an example of try/catch logic.


var msg = $context.currentItem.previousItem;
var authId;
var wasFound;
     authId = msg.getResponse(msg.RESPONSE_HTTP_BODY_AS_JSON, "//authid")[0];
      wasFound = true;
catch (e)
// 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;

if (wasFound)
// Do something here (found).
// Do something else here (not found).