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. It has a single configuration option:

  • Condition: A Jsonata expression that produces a boolean result (true or false). This result determines whether the then path or the else path will execute.
    • Example: If the condition is response.data.role = "admin", 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 variable values or response data.


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. The Loop Node has several configuration options:

  1. Repeat Times: An integer specifying the number of times to repeat the loop. This is required.

    • Example: Set Repeat Times to 10 to execute the loop 10 times.
  2. Break Condition (Optional): A Jsonata expression that produces a boolean result. This condition determines whether the loop should continue or break early.

    • Example: If the condition is response.data.status != "completed", the loop will break as soon as status is “completed”.
  3. Delay (Optional): Adds a delay (in seconds) between each loop iteration, which can be helpful for throttling or time-sensitive tests.

  4. Context Key (Optional): The context key to store the current loop index. This allows you to reference the index in other nodes within the loop.

    • Example: Set Context Key to createPostIndex. Within the loop, you can then access the current iteration index using context.createPostIndex, which is helpful for labeling or tracking iterations.

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. This node has two key configurations:

  1. Context Key: This key stores the current iteration item, allowing you to access both the index and value during each iteration.

    • Example: Set Context Key to userItem, then use {{context.userItem.index}} to access the current item index and {{context.userItem.value}} for the item’s value.
  2. Data Source: Determines the source of the data list to iterate over. You can choose between:

    • 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 context.
      • Example: Set the expression 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.