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

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

General methodologies

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

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

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

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

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

For a Message:

 

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

Click 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 property path (or "in situ substitution expression" —ISSE) into the field for you. Now, before the Message is sent, the current value of the property will be inserted.

For an Action:

 

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

Click 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. If the property doesn't exist, scroll down, set the property at the necessary level (i.e. CurrentAppAction or CurrentBrowserAction in a WebUI clip). Enter a name for the new custom property and then click OK.

SOASTA CloudTest inserts the appropriate "in situ substitution expression" (ISSE) into the field for you. Now, before the 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 Action, the entered text may contain one more embedded ISSE (in situ substitution expression) specifications. 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 Scripting 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 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" Action.

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

Any Script can traverse the object hierarchy of the Test Composition, find Messages and 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 Action.

You will need to arrange the timing to be such that the Script plays before the play of the Message(s) or 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 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);

 

Attachments

    Outcomes