Using JavaScript to create Property Structs

Document created by Dave Murphy Employee on Jul 19, 2017
Version 1Show Document
  • View in full screen mode

JavaScript does not distinguish between Objects and Structs in standard implementation, however CloudTest properties do not classify a JS Object as a Struct.

 

To counter this, the CloudTest API implements a Struct() object type to allow the creation of a struct within a script, which can then be stored into a property and referenced correctly.

 

The below example will create an address struct to be referenced later as a property.

 

// Get the extracted address // Extracted address follows the <street>,<city>,<State>,<Zip> format // For example, extracted value may contain: // 444 Castro Street,Mountain View,CA,94041  var addressCSV = $prop.value("clip","addressCSV");  // Split the components by comma var addressArray = addressCSV.split(",");  // Create a new Struct var addressData = new Struct(); // Note: this is an internal CT Object Type  // Assign the values addressData.Street = addressArray[0]; addressData.City   = addressArray[1]; addressData.State  = addressArray[2]; addressData.Zip    = addressArray[3];  // Save struct to clip $prop.set("clip","addressStruct",addressData);

 

From here, the addressStruct clip property can be referenced like any other struct inside the clip, by appending the Struct key to the property name in an ISSE.

 

For example, if I wanted to substitute the street value into the request body, I would use the following ISSE inside my clip:

 

{%% prop : parent-clip : ./addressStruct.Street %%}

Attachments

    Outcomes