# Loops beta
Loops in Virtuoso provide a simple yet powerful way to repeat test steps within checkpoints. This feature enables you to loop over checkpoints without the need for complex scripting, eliminating the need for manual duplication of repetitive steps, streamlining test automation workflows while maintaining efficiency and clarity.
# Who should use this feature?
- Users who need to validate multiple UI elements dynamically (e.g., image carousels, product bundles, retry operations) or require loops that automatically adapt to test data variations.
- Teams looking to streamline test workflows without writing complex scripts.
# Key benefits
- Simplified test design: Configure loops with a simple toggle between Fixed and Conditional modes.
- Efficiency: Loops adapt dynamically to test conditions, skipping unnecessary steps.
- Customization: Users can define their own execution logic via conditions.
# How it works
Loops are configured within the context of a specific journey and are not properties of checkpoints themselves. This means that setting a loop on a checkpoint in one journey has no effect on the same checkpoint in any other journey. Each journey's loop configuration is independent, ensuring that loops apply only to individual checkpoints within that particular journey and do not extend across multiple journeys.
Virtuoso offers two modes for configuring loops — Fixed and Conditional — to accommodate different testing needs. Whether you need a specific number of iterations or dynamic behavior based on conditions, loops make it easy to streamline repetitive tasks and adapt to varying test scenarios.
# 1. Fixed mode
- The checkpoint executes a specific number of times (up to 10).
- Users can enter a static number or use a variable to define iterations.
- Example: Checking 10 carousel images by iterating through each one.
# 2. Conditional mode
- The checkpoint executes based on a JavaScript condition.
- Users can enter a static number or use a variable to define the max number of iterations (up to 10).
- The loop stops running once the condition evaluates to false.
- Example: Polling an API response every 5 seconds until valid data is received.
# Configuring loops
Loops can be configured in one of two modes. This section walks you through the steps to enable and configure loops.
# Step 1: Enable loops on a checkpoint
- Open a journey and navigate to the checkpoint where loops are needed.
- On the checkpoint options, select the option Add loop.
# Step 2: Select loop mode
- Choose either Fixed or Conditional mode.
# Fixed mode configuration
- Select Fixed as the loop type.
- In the Iteration Count field, enter a number (max 10) or a variable (e.g.,
$iterations
). - Click Save to apply the settings.
# Conditional mode configuration
- Select Conditional as the loop type.
- Enter a maximum iteration count (max 10).
- In the Condition field, enter a JavaScript expression to control execution.
- Example:
$response?.status !== 200
(loop will continue until the API returns200
).
- Example:
- Click Save to apply the settings.
Loops limitations
Loops are limited to a maximum of 10 iterations. This limit is enforced in both modes of loops, Fixed and Conditional.
# Skipping checkpoint execution due to loop configuration
A checkpoint may not be executed if:
- The iteration count is set to
0
(or evaluates to0
using a variable). - The condition in a Conditional loop evaluates to
false
on the first run.
# Example use case
A test should run only if a specific value is present in a dropdown. If the value doesn’t exist, the entire checkpoint is skipped.
# Key use cases
# 1. Testing carousel images
A user needs to verify images, titles, and links in a carousel. Instead of duplicating steps, loops iterate through stored values for each image variation.
# 2. Scroll bar testing
A tester needs to validate if a scroll bar is shown inside a currency dropdown in cases where it has at least 10 currencies. Since the initial number of currencies may vary, a checkpoint first checks the list length and adds a currency if needed. This repeats until 10 currencies exist, ensuring accurate UI validation.
# 3. Handling product bundles and add-ons
A test must handle different numbers of add-ons per product bundle, as defined in test data. A loop automates the addition of items based on the number of add-ons listed in the test dataset, eliminating manual repetition.
# 4. API polling
A user needs to verify data synchronization between Salesforce and NetSuite, which can take 15-40 minutes. The test makes an API call every minute until correct data is received, preventing unnecessary execution of subsequent steps.
# Authoring with loops
Authoring a looped checkpoint shares the same capabilities as authoring any other checkpoint.
We also offer a few utilities that can help you during the creation of steps inside a loop:
- Step details per iteration: You can view step information for each iteration of a test step, allowing you to fully understand what happened in each iteration.
- Loop condition evaluation: The first step of each iteration will also display the result of the loop condition.
- Access the iteration number: If you need to know the iteration you’re in within a looped checkpoint step, you can use the variable
$VIRTUOSO_CONTEXT.loopIteration
. This variable contains the current iteration number. This variable contains the current iteration number, which starts at 1. - Breakpoints: You can set breakpoints for a specific step in as many iterations as needed. Additionally, you can quickly create a breakpoint for a single iteration or all iterations.
- Loop summary: You can quickly inspect the outcome of each iteration by hovering over the Loop iteration outcome.
Notes & Considerations
- Conditional loops iterations: In conditional loops, execution rows are pre-allocated for the defined maximum number of iterations. If fewer iterations are needed, some rows remain unused and are skipped.
- Scope of loops: Loops apply only to individual checkpoints and do not extend across multiple checkpoints.
- No nested loops: You cannot place one loop inside another.
- Checkpoint skipping: If the loop condition evaluates to
false
before the first iteration, the checkpoint is skipped. - Library checkpoints: Loops configuration are not persisted in Library Checkpoints, as looping is tied to a specific journey.
- Condition handling: If a Conditional loop’s condition never evaluates to
false
, execution stops at 10 iterations to prevent infinite loops.