StartLoop and EndLoop Logical Looping Constructs

This topic explains both StartLoop (begins the loop; no inputs) and EndLoop (ends the loop; takes inputs in the Inputs column).

Looping is confined to a single test script. Nested or overlapping loops are not supported.

Repeat a block of test steps until a condition becomes true or a maximum iteration count is reached. This eliminates long static waits and supports asynchronous or event-driven scenarios.

Using Logical Looping Constructs

  • Poll for backend or workflow-driven updates (for example, query a record until a status changes) and then continue the test.
  • Replace brittle sleep/wait statements with controlled, condition-based repetition.

Keyword Usage and Inputs

  • StartLoop
    • Inputs: A variable name, to get iteration count, automatically initialized to 1 and incremented each iteration.
    • Can be the first step in a test script.
  • EndLoop
    • Inputs (provided in the Inputs column, not the Condition column):
      • Condition: A Boolean expression that, when it evaluates to true, exits the loop.
      • Max_loop_iterations: A positive integer cap; the loop exits when this count is reached if the condition has not become true.
    • Script-level inputs take precedence over profile defaults.

The loop exits immediately when the Condition evaluates to true; otherwise, it runs up to Max_loop_iterations.

Defaults and Guardrails

  • You can configure a test execution profile-level loop iterations limit to cap loops if EndLoop parameters aren’t set.
  • If neither EndLoop parameters nor a profile cap are provided, a small default cap applies to prevent infinite loops.

Data-driven tests: Steps inside the loop can consume dataset values; each iteration uses the current dataset row according to existing behavior.

Reruns: Looping does not change rerun behavior; on rerun, the script starts from iteration 1.

Validation and Restrictions

  • Nested or overlapping loops are not permitted. Attempting to start a new loop before ending the previous one results in an error.
  • If StartLoop’s test step condition (if used) evaluates to false, the entire loop block is skipped, EndLoop is ignored, and execution continues after the block.
  • StartLoop and EndLoop must be in the same test script; cross‑test‑script loops are not supported.

Error Handling

  • EndLoop condition expression:
    • Syntax errors or use of uninitialized variables cause a clear failure message at runtime.
  • Invalid Max_loop_iterations (for example, negative or non-numeric):
    • Treated as invalid input; the loop does not execute and an error is reported.
  • Orphan EndLoop (no preceding StartLoop):
    • Reported as a failure; the script continues with subsequent steps, and the test script is marked failed.
  • Multiple StartLoops before a matching EndLoop:
    • Reported as an error (nested/overlapping loops are not supported).

Reporting

  • Per-iteration logging:
    • Log “Start Iteration: n” at loop begin and “End of Iteration: n. Expression evaluated: <value>” at loop end.
  • Results import:
    • Only the latest iteration’s results (pass/fail) are imported into the Test Results view.
  • Mid-iteration failures:
    • Log all executed steps up to the point of failure; remaining steps in that iteration are not executed.

Configuration

  1. Test Execution Profile:
    1. Set “Loop iterations limit” value, that will take effect in absence of a value for Max. iterations in EndLoop
  2. If and when provided in EndLoop Test Step, it will override profile value.

Best Practices

  • Always specify at least one exit guard (Condition or Max_loop_iterations); preferably specify both.
  • Include a refresh or re-query step inside the loop so the condition evaluates updated data each iteration.
  • Keep iteration caps and timeouts reasonable to avoid long-running tests.
  • Validate condition expressions in unit or batch runs before production runs, and initialize variables in profiles or earlier steps.

Examples

Example 1: Loop until condition

  • StartLoop
  • Query record or perform a refresh action
  • EndLoop - Condition: @Status = "Completed"

Behavior: Repeats steps until @Status becomes Completed; exits immediately when true. @counter is initialized with 1 and incremented for iteration. Use the variable within or outside the loop.

Example 2: Loop with condition and max iterations

  • StartLoop
  • Poll service request status
  • EndLoop Inputs: Condition = @SRState = "Closed"; Max_loop_iterations = 5

Behavior: Exits when SRState is Closed or after 5 iterations, whichever occurs first.

Example 3: StartLoop as first step in the test script

  • StartLoop
  • Launch App (for example, uses @user)
  • Perform steps
  • EndLoop Inputs: Condition = @Ready = true

Behavior: The section between StartLoop and EndLoop repeats; launch and steps execute each iteration as scripted.

Troubleshooting

Error Fixes

Loop exits too early or never exits.

Verify the condition logic, ensure data is refreshed within the loop, and set a reasonable iteration cap.

Tests run longer than expected.

Tighten the exit condition, reduce the cap, or use the profile limit.

Runtime expression failures.

Fix syntax, initialize all variables used in the condition, and retest in unit/batch modes.

Note:
  • No nested or overlapping loops.
  • Loop scope is limited to one test script; EndLoop must follow StartLoop in the same test scriptscript.