Array File

Using an array file from a script (using JavaScript), you can insert values into a test. This method works well for random users.

Your script should include the following:

  • Seed data array. Place the array inside the Javascript itself.
  • Data Selection from that array
  • And a property setting using the data from the array

How to

  1. First, you build the array of desired data. The array will be declared in the script file and will look like this: var oStrings = ["Value1","Value2"]; Arrays require a special format. On the right, an example of declaring a variable named oStrings and setting its value to an array.
    • The data for any array starts with '[' and ends with ']'
    • Terminating any JavaScript line uses the semicolon ';'
    • The values inside the array should be wrapped in double quotes
    • At the end of a value, you have a comma before the next value
    
    
    
    
     var oStrings = [ "PG3032901074056", "PG3052321074056", "PG3062641074056", "PG3082651074056", "PG3182821075056", ];
  2. Next, you have to have code that 'selects' or 'chooses' a value from the Array. This extraction will also set the value extracted into another variable.Here 0 is the index for which value we are pulling from the array. This index can be specified or obtained randomly. Arrays use numerical indexes. Usually starting with 0. You can get a value from the array with this syntax: oStrings[0] This gets the 0th index from the array. When you pull from the array, you have to specify the index you want from it.Note: If you choose an index that does not exist, you will get an "Index Out of bounds" error. var getValueFromArray = oStrings[0]; An example of random extraction: var a = oStrings[Math.floor(oStrings.length * (Math.random()))];
  3. Once you have chosen the value from the Array, take that selected value into a property that the clip can use.

What you should see

In the example on the right:

  • MessageClip is the scope of the property, or where it lives.
  • NameOfPropertyInClip is the name we will use in the Clip to pass this value.
  • getValueFromArray is the JavaScript variable name that we used to store the value we extracted from the Array

$prop.set("MessageClip", "NameOfPropertyInClip", getValueFromArray);

There are two ways to set properties in CloudTest:

  • Seed data such as from an index from an Array or terms to use in a Search
  • Extracted Values. Example: After logging into a site, we need to extract data and put that data into a property in order to pass it to all the Messages that come after. For example, a SessionID. See Extract a sessionID for more information about extracted values such as sessionID(s).

In the example on the right, we are setting a clip property with the name of scriptSessionId to the value of the variable in the JavaScript from the array extraction.

$prop.set("MessageClip", "scriptSessionId", scriptSessionId);