Miscellaneous ScriptsThis topic presents miscellaneous SOASTA CloudTest scripts. Scripts 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 s ript. Shorter scripts are presented inline (in the right column). |
|
Miscellaneous Scripts |
|
In those cases where you need a script to skip playing the remainder of the current repeat of the current test clip, you would do: |
|
If the clip was serially repeating and you want to end it completely, including stopping it from repeating any further, you would do: |
|
If the clip was serially repeating and you wanted the current repeat to finish, but not repeat any more after that, you would do: |
|
Optionally, if you want to cause the container to error out, supply error text like in the following example: |
|
msg.clearResponse();) is the main part of this script. It is useful for ensuring that large responses do not stay in memory if they are no longer needed.
|
|
This Random Think Times script resets all subsequent delays to have a random think time between the interval specified in the script below. If you want to set all delays to zero, just set both the minimum and maximum delay times to zero. |
|
Immediately aborts play of the current Script, and considers the Script to have failed with the given error text. If no error text is provided, the text “Script aborted.” is used. So, for example, in those cases where the eval/throw statement is used (such as in the Validation Scripts), you could instead do: |
|
This overrides a target to either use or not use SSL (i.e. HTTP to HTTPS or vice versa). |
|
Stopping a composition using a script is a simple, one-line operation calling the |
|
This example shows how to URL encode text. This is useful in cases where certain characters like a plus sign (+) need to be encoded to go on a URL – as %2B. This script is also useful because it shows how to create a function that performs the encoding. This function can be called multiple times in the script. |
|
Another example of using the replace function to do encoding is presented in the right column. This script uses different statements for each replacement rather than combining them together (as the first example shows). |
|
The example script on the right is not run in a separate script object – it is run directly in the query string parameter of a message. In this example, it is adding the VUNumber property value to 500. Note: all properties are a string, so the property needs to be converted to a number before it can be used in math calculations. |
|
This creates an array with all of the values of the href tags in the response. |
|
|
To print out the values in the result as a comma-separated list: |
|
|
To print out the values in the result as separate lines: |
|
The Determine dates 30 and 31 days from now script calculates today's date in the individual pieces of month, day, and year in both 2 and 4 digits. It then calculates two other dates in individual parts based on today's date. These two dates are 30 and 31 days into the future from today's date. |
|
The following brief script reads a clip property into a test using a variable.
|
|
The brief script on the right is used to trim spaces from a string. |
|
The Conditional Logic using Chains and Random Numbers script plays a chain 10% of the time and turns it off the remaining 90% of the time. |
|
Lines 12-14 generate a random integer contained within the two extremes. |
|
|
Line 20 creates a variable, chain, that gets the child of the name specified. |
|
|
Lines 23-25 generate a random number between 1-10. |
|
|
Use the var, num1, from above to play the clip, otherwise set it to 0 using |
|
This simple script replaces any spaces in the |
|
This script precedes a chain in a test clip and sets the number of chain repeats to 10 dynamically during test execution. |
|