Find Out How

Print Friendly Version

How do I dynamically or programmatically substitute a value into a Message or Browser Action before it is sent or played?

General methodologies

There are three major methods that can be used to substitute a value into a Message or Browser Action before it is sent or played:

  1. Substitute property values using the Message and Browser Action editors.
  2. Manually enter "in situ substitution expressions" (ISSE).
  3. Use Scripts to modify Messages or Browser Actions.
 

Method 1 - Substitute a property value using the Message and Browser Action editors

Custom Properties, Global Properties, and System Properties can be substituted directly into a portion of a Message or Browser Action before it is sent.

You will need to arrange for the value of the property used to contain the desired value before the insertion. For example, a Custom Property could be set by a Script or from a portion of a response to a prior Message or Browser Action. A Global Property could be set manually or could be set by a Script or from a portion of a response to a prior Message or Browser Action.

For a Message:

 

Edit the Message into which the property value is to be inserted, and find the desired portion of the Message into which the value is to be inserted, in the "Inputs" section.

Click on the "Property Chooser" icon to the right of the input field to bring up the "Property Chooser" dialog.

Find the property in the list, and select it. Click OK.

SOASTA CloudTest inserts the appropriate "in situ substitution expressions" (ISSE) into the field for you. Now, before the Message is sent, the current value of the property will be inserted.

For a Browser Action:

Edit the Browser Action into which the property value is to be inserted, and find the desired portion of the request into which the value is to be inserted, in the "Inputs" section. In this example, the property value is to be used as the Locator.

Click on the "Property Chooser" icon to the right of the input field to bring up the "Property Chooser" dialog.

Find the property in the list, and select it. Click OK.

SOASTA CloudTest inserts the appropriate "in situ substitution expression" (ISSE) into the field for you. Now, before the Browser Action is played, the current value of the property will be inserted as the Locator.

Method 2 - Manually entered "in situ substitution expressions"

Any place where a value is manually entered for a portion of a Message or Browser Action, the text can contain one more embedded "ISSE" (in situ substitution expression) specifications within it. Any such specifications will be evaluated and replaced with the resulting value. An ISSE can reference properties, contain a simple expression, or full Scripting. Refer to the documentation on ISSEs for more information.

Example for a Message:

 

This example shows an ISSE containing a small Script that produces the current date. The result of the ISSE is appended to the text "XX-" to form the value that will be sent in that field of the Message.

Example for a Browser Action:

This example shows an ISSE containing a small Script that produces the value of the current Test Clip's property named "Test Clip property 2" added to the number 350. The result of the ISSE is inserted into the middle of the text starting with "a, " and ending with ", z" to form the value that will be used as the Value for the "Type" Browser Action.

Method 3 - Use a Script to modify the Message or Browser Action

Any Script can traverse the object hierarchy of the Test Composition, find Messages and Browser Actions, and change portions of their message or request. This method allows the highest degree of customization, since you can add complex custom logic to the Script to change the Message or Browser Action.

You will need to arrange the timing to be such that the Script plays before the play of the Message(s) or Browser Action(s) that the Script modifies.

Refer to the Scripting documentation for the details of how to write a Script, traverse the Test Composition object hierarchy, and modify Messages and Browser Actions.

Example snippet of Script code for a Message:

// Get the Message that immediately precedes this
// Script.
var msg = $context.currentItem.previousItem;

// Get the current body of the HTTP message.
var msgBody = msg.getMessage(msg.MESSAGE_HTTP_BODY);

// Insert code here to make any desired modifications
// to the HTTP message body...

// Put the modified HTTP body back into the message.
msg.setMessage(msgBody, msg.MESSAGE_HTTP_BODY);

 

Example snippet of Script code for a Browser Action:

// Get the Browser Action that immediately precedes
// this Script.
var action = $context.currentItem.previousItem;

// Get the current parameters for this Browser Action.
var params = action.getRequest(action.REQUEST_OPERATION_PARAMS);

// Change the second parameter of this Browser Action.
// (You would insert custom code as appropriate
// to determinehow the parameters should be
// modified.)
params[1] = "new value";

// Put the modified parameters back into the Browser
// Action.
action.setRequest(params, action.REQUEST_OPERATION_PARAMS);