Adding For Loops in Test Cases


For Loops are a powerful tool that will let us repeat operations. A For Loop loops a block of steps through each dataset (which is a multi-column, multi-row variable) in a test data profile. The loop ends when it reaches the end of the dataset or when a break is encountered.

Thus using For Loops, you can run the same test with a subset of test data. For instance, say you have a test data profile in the format below:

test data example

If you want to run a test case based on the above test data profile, but you just want to run it for rows 1 to 3, then you use a for loop.


Prerequisites


Using For Loop in Test Cases

  1. Navigate to Create Tests > Test Cases, and click on Create Test Case. Create Test Case
  2. On Test Case Details page, click on the option on the left side of the test step. Option on Test Step
  3. This will open a side panel. Side Panel
  4. Hover over to the options and click on For Loop. For Loop
  5. This option opens a drop down of NLPs that can be used inside the test step. For Loop NLPs

    • If you want to iterate through all the data sets of your test data profile from start to end use the below NLP: index start to end
    • If you want to start the index at a specific number and end the index at a specific number use the below NLP:specific_index_number

    Sometimes you only want to work with a subset of the data sets of your test data profile. The subset of the data sets can be filtered based on data set name and parameter.

    • To filter test data profile based on data set name use the following NLP: for loop set name

    The data set names can be subjected to advanced filtering based on the keywords contains,startswith,endswith,IN and the different data types supported by Testsigma. For more information refer to data types .

    • To filter test data profile based on parameter value use the below NLP: for loop parameter value
    • Another NLP to filter test data profile based on parameter value is the following: for
  6. Select the suitable NLP to include in the test step and finish creating For Loop test step.

Additional actions possible on iteration count

  1. Store: Iteration count is the current count that is being iterated in a for loop in Testsigma. This Iteration Count can be stored into a variable for later use. Below is how the syntax for the Store NLP looks like:

store-iteration-count-test-data-set-name

  1. if: The test data set values, from a test data profile being iterated, can be compared within an if condition too. Below screenshot shows the NLP (The NLP can be added as a part of add-on “String Compare”. You can find the add-ons to use here: https://testsigma.com/addons):

the verify if NLP that is available with the addon String Compare