Webtest WebTest GitHub Home

Core Step repeat

Description

This step encapsulates one or more test steps that shall be repeated a certain number of times. Any kind of step can be nested.

This is useful when you want some test to be repeated a given number of times. To facilitate reporting, nested steps are wrapped in an "Iteration wrapper" step for each execution.

The actual repetition counter is made available to the steps included in the <repeat> step by a dynamic property. Its default name is "count" unless modified by the countername attribute. This property can be referenced by steps nested in the <repeat> step using this notation "#{count}" (resp. the specified countername).

When used with xpath, <repeat> performs one iteration per node given by the evaluation of the XPath expression and places the current node in the global variable context under the name specified by the countername attribute. This makes the current node availabe for xpath expressions in <repeat>'s nested steps with the syntax "$count" (resp. the specified countername).

Parameters

count
Required? yes/no
The number of times that the included steps shall be executed. Specify either count or endCount. Counter values start at startCount and go up to startCount + count - 1.
counterName
Required? no, default is count
The name that shall be used to reference the current repetition counter.
description
Required? no
The description of this test step.
endCount
Required? yes/no
The final value of the count. Specify either count or endCount. Counter values start at startCount and go up to endCount.
startCount
Required? no, default is 0
The initial value of the count. Doesn't affect the number of iterations, just the value appearing in the counter.
step
Required? no, default is 1
The step size of the count. Doesn't affect the number of iterations, just the value appearing in the counter.
xpath
Required? yes/no
Specifies the XPath expression which evaluation gives the results on which to iterate

Nested Parameters

step
Required? yes
A webtest step.

Details

The following example illustrates the most simple usage of a <repeat> step and shows how to reference the repetition counter via its default name.

repeat 1
<webtest name="Create repetitively N user">
  <config ... />
  <steps>
    <repeat count="2">
      <invoke description="Create user"
        url="addUser?name=TestUser#{count}"/>
      <verifyText description="Check success message"
        text="User successfully created" />
    </repeat>
    ...
  </steps>
</webtest>

This example shows two nested <repeat> steps where each uses a specific countername in order to access within the innermost <repeat> step both values.

repeat 2
<webtest name="Iterate over all cells in a table">
  <config ... />
  <steps>
    <repeat count="2countername="row">
      <repeat count="2countername="column">
        <invoke description="Show a particular table cell"
          url="showCell?column=#{column}&amp;row=#{row}"/>
        <verifyText description="Check cell contents"
          ... />
      </repeat>
    </repeat>
    ...
  </steps>
</webtest>

This example shows how the xpath attribute allows a compact syntax

repeat with xpath
<webtest name="Verify details of each client">
  <config ... />
  <steps>
    <invoke description="get the client listurl="/myClientsList"/>

    <repeat xpath="//table[@id='clientList']//trcounterName="curRow
        description="iterate on all rows of the table">
      <storeXPath xpath="$curRow/td[4]property="lastName
        description="store client's last name"/>
      <clickLink xpath="$curRow//a[@class='detailPopup']
        description="open the detail popup"/>
      <verifyText text="#{lastName}"
        description="Check that the detail of the selected client are displayed"/>
    </repeat>
    ...
  </steps>
</webtest>