Iterate – Source Reference


The Iterate <IterateData> element can iterate over data items that it references. It is a Composite element and for each iteration it will execute its sequence of elements. It will update a variable named after its ID with the data that the current iteration represents. Child elements to the Iterate element can access this data at runtime.

Syntax
The syntax of the IterateData element is:

<IterateData id="<id>"
 referencedId="<refId>"
 dataPath="<path>">
<!—Sequence of elements to execute-->
</IterateData>
  • The ID is used for child elements to refer to the actual iteration data
  • The referencedId points to the Referenceable element that contains data to iterate
  • The optional dataPath points out the data in the Referenceable element to use for the iteration

Example
In the example below, the IterationData iterates over a complex variable called var that contains three A data items. The iteration will put the current data item as value for the loop ID. It will iterate three times and for each iteration, the Data Reference element will point out the value of the B element under the current A element and it will be written to the console.

<Variable id="var">
<A><B>b1</B></A>
<A><B>b2</B></A>
<A><B>b3</B></A>
</Variable>
<IterateData id="loop" referencedId="var" dataPath="/A">
<Log>
  <data:Replaceable>
<DataReference referencedId="loop" path="/A/B/*" />
  </data:Replaceable>
</Log>
</IterateData>

The next example first uses an SQLSelect element to select rows from a table. The IterateData loops over all rows that are returned. The SQLSelect statement does not contain a Row element, which we refer to inside the iteration in the Data Reference element. The Row element does not exist at the time of building the test scenario. However, it will be produced when the test scenario executes, and then the Data Reference will be able to access the data. The UI part of Non-virtualized Test knows about this and lets you select correct values when you use it with Iterate and Data Reference.

<SQLSelect id="sql" maxRows="20">
<Statement>SELECT A,B FROM C</Statement>
<Output name="A" />
<Output name="B" />
</SQLSelect>
<IterateData id="loop1" referencedId="sql" dataPath="">
<Log>
  <data:Replaceable>
<DataReference referencedId="loop1" path="/Row/A/*" />
  </data:Replaceable>
</Log>
</IterateData>

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*

BMC Compuware Topaz Workbench 20.06