While Loop in Test Cases


In Testsigma, you can create a while loop to execute a test step repeatedly if a specified condition remains true. While Loop iterates through the step until the condition becomes false and then stops executing the test step and moves to the next test step. This article discusses using While Loop in Testsigma.


Prerequisites:


Using While Loop in Test Cases

  1. Navigate to Create Tests > Test Cases, and click on Create Test Case. Test Cases
  2. Create a test step to navigate to the URL. Example: https://demoqa.com/webtables Navigate to Website
  3. Click on the option on the left side of the test step. Option
  4. This will open a side panel. Side Panel
  5. Hover over to the options and click on While Loop. While Loop
  6. This will add a while condition in your test step. While Condition
  7. Now add the test step within the While Loop by choosing the specific NLP. While Loop Step
  8. Hover over the test step and click on Step Inside Loop to add sub-steps under the While Loop. Step Inside While Loop
  9. This will create a test step number 2.1 which will be under step 2. Step 2.1
  10. You can continue to add sub steps numbered as either 2.2, 2.3, or as 3,4, etc. The test steps numbers 2.2, 2.3, etc will be executed only if the While Loop stops.

Here's a quick GIF demonstrating using While Loop in Test Cases. While Loop GIF


Adding While Loop in Test Cases Using Recorder [Web & Mobile web]

  1. Navigate to Create Tests > Test Cases, and click on Create Test Case. Test Cases
  2. Click on Record. Record
  3. A new window will be opened with recorder. New Window
  4. Go to https://demoqa.com/webtables. Website
  5. Hover over the option highlighted on the recorder and click on While Loop. While Loop
  6. Add the step and click on Add Step Inside to record the steps inside the while loop. Add Step Inside
  7. Click on Done. Done

For more information on creating steps using recorder, refer to recording test steps.


Adding While Loop in Test Cases Using Recorder [Android & iOS]

  1. Navigate to Create Tests > Test Cases, and click on Create Test Case. Test Cases
  2. Click on Record. This will open Record test steps overlay. Record
  3. Select the Test Lab, Test Machine, App Source and click on Record. Test Lab, Test Machine, App Source
  4. Wait until the virtual app is loaded.
  5. On Testsigma Recorder, click on the option highlighted and click on While Loop. While Loop
  6. Record all the steps and click on Stop Recording to quit the session. Stop Recording
  7. You’ll be redirected to the test case creation page where you can see the recorded steps. Test Case Details

Here's a quick GIF demonstrating adding While Loop in test cases using the recorder. GIF Mobile Apps


Additional actions possible on iteration count

  1. Store: Iteration count is the current count that is being iterated in a while loop in Testsigma. This Iteration Count can be stored into a variable for later use as well. 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