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

Add for loop to test case

  1. Create a test case and inside the test case, create test steps to be run before the for loop.
  2. Create the test data profile . Once the test data profile has been created, the for loop can be added in the test case to iterate through the rows of the profile.
  3. Hover over the menu adjacent to the test step on the left. This should open the menu with different test step options as shown below: for loop
  4. Select for loop from the list. This option opens a drop down of NLP’s that can be used inside the test step. for loop nlp options
    • 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
      Refer to the below GIF for the usage of the 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 nameThe 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 .
      Refer to the below GIF for the sample usage of the NLPfor loop setname contain
    • To filter test data profile based on parameter value use the below NLPfor loop parameter value
      Refer to the below GIF for the sample usage of the NLP:parameter value
    • Another NLP to filter test data profile based on parameter value is the following: for
      Refer to the below GIF for sample usage for loop not empty
  5. Select the suitable NLP to include in the test step.
  6. Finish creating the for loop test step by clicking on Create button.

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