Traverse the Object Hierarchy

Document created by Chris Sommerstad Employee on Jul 22, 2017Last modified by Dave Murphy on Sep 26, 2017
Version 2Show Document
  • View in full screen mode

The following script provides an example of how to traverse the SOASTA CloudTest Object Model. Since both $prop and $sysprop provide easy shortcuts for accessing properties in a Test Composition without having to traverse the object model this script is likely unnecessary and is presented only as an alternative method.

Note:  Use the following links to download and import the XML for the entire Object Hierarchy Composition or just the Object Hierarchy Script or copy and paste the script code from here.

XML can be imported using the Etc. menu (...) > Import command. If you import this entire composition, you will need to change the target’s URL to use your CloudTest server name (or IP address) instead of “localhost”. You can do so by opening the Object Hierarchy target in Central list > Targets and replacing the text in the URL field.

Refer to Script to learn how to add a script to a test clip and test composition.

  1. The variable "tree" will end up with the text that is to be posted to the result object.  Start out with an empty string.

var tree = "";
  1. Define a function called displayItem to construct displayable text for a given item in the Composition. If no item was given (the input is null), construct the appropriate text.

function displayItem(item, indent) 
if (item == null) {
  tree += indent + "(null)";
  1. Display the name and type of this item.

     tree += indent + "Item: \"" + +
      "\", type: " + item.type + "\n";

  4. Determine if this item has any children, and if not construct the appropriate display text.

 var children = item.children;
 if (children == null)
 tree += indent + " (none)\n";

  1. If this item has children, call displayItem recursively to display each of them.

   for (var i = 0; i < children.length; i++)
   displayItem(children[i], indent + " ");