Logic Nodes: If, Loop, and Iteration Nodes

Logic nodes in ReAPI provide control over the flow of test cases, allowing you to create conditional paths, repeat steps, and iterate over data sets. Here’s a guide to each of the logic nodes and how to configure them effectively.


If Node

The If Node is used to control conditional branching in your test flow.

ConfigurationDescriptionExample
ConditionA Jsonata expression that produces a boolean result (true or false). This condition can only access context values and determines which path to execute.First store your API response in context (e.g., context.role = response.data.role), then use context.role = "admin" as the condition. The then path will execute if the role is “admin”; otherwise, the else path will be followed.

This node is essential for tests where different actions need to occur based on values stored in the context.


Loop Node

The Loop Node allows for repeating a set of nodes multiple times. It is especially useful for testing scenarios that require repetitive actions, such as creating multiple records or testing load limits.

ConfigurationRequiredDescriptionExample
Repeat TimesYesAn integer specifying the number of times to repeat the loop.Set to 10 to execute the loop 10 times.
Break ConditionNoA Jsonata expression that produces a boolean result. This condition can only access context values and determines whether the loop should continue or break early.First store your API response in context (e.g., context.status = response.data.status), then use context.status = "completed" as the break condition. The loop will break when the context value matches the condition.
DelayNoAdds a delay (in seconds) between each loop iteration, which can be helpful for throttling or time-sensitive tests.-
Context KeyNoThe context key to store the current loop index. This allows you to reference the index in other nodes within the loop.Set to createPostIndex. Within the loop, you can then access the current iteration index using context.createPostIndex.
Start IndexNoAn integer that specifies the starting value for the loop index when Context Key is configured. Defaults to 0 if not specified.Set to 1 to make the loop index start from 1, producing sequence 1,2,3… instead of 0,1,2…

Iteration Node

The Iteration Node is used to iterate over items in a list. Each item in the list is processed individually in each iteration.

ConfigurationDescriptionExample
Context KeyThis key stores the current iteration item, allowing you to access both the index and value during each iteration.Set to userItem, then use {{context.userItem.index}} to access the current item index and {{context.userItem.value}} for the item’s value.
Data SourceDetermines the source of the data list to iterate over. Two options available: • Inline Data Source: Directly input a list of data items to iterate over • Expression Data Source: A Jsonata expression that retrieves a list from the contextFor Expression Data Source: Set to context.usernames to iterate over a list stored in context.usernames.

Why Logic Nodes are Powerful

Logic nodes make your test cases dynamic and adaptable by enabling conditions, loops, and data-driven iterations within the flow. By using conditional paths, repeating steps based on real-time data, and iterating over data sets, you can create comprehensive and versatile test scenarios that mimic real-world use cases with ease. These features allow for more accurate, reusable, and efficient tests across diverse API testing needs.