Using list tags in ECMAScript

You can write ECMAScript functions that manipulate the values in a multi-value tag. The Java ArrayList class is available for multi-value tags in custom functions that you write in HCL OneTest API. Not all methods are guaranteed to work.

For general information about scripting, see Scripts within tests and stubs.

In the following example script, the numbers.get() method returns the value corresponding to the specified index, and the numbers.add() method appends a new value to the list.

// Get the last two numbers in the list, and convert them to numbers:
var beforePrevious = parseInt(numbers.get(numbers.size() - 2));
var previous = parseInt(numbers.get(numbers.size() - 1));

// Add 10 more numbers to the list
for(var i=0; i<10; i++) {
  // Calculate the next number to add to the list
  var next = beforePrevious + previous;

  // Add it to the list
  numbers.add(next);

  // Update the variables for calculating the next number
  beforePrevious = previous;
  previous = next;
}