Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Number Value
    If the loop source is a number value then the test case inside loop will be executed specified number of times. 
  2. Variable Name 
    1. If the variable's value is a number then the test case inside loop will be executed n (n is the variable's value) number of times.
    2. If the variable's value is an array then the test case inside loop will be executed n (n is the length of array) number of times.
    3. Otherwise the variable's value will be treated as boolean 
      1. if the variable's value is truthy then test case inside loop will be executed.
      2. Otherwise test case inside loop will loop will not be executed.
  3. Any Other ValueIf the loop source is neither number nor variable then loop source will be treated as boolean value.Boolean Value
    1. If the value is truthy false then test case inside loop will not be executed.
    2. Otherwise test case inside loop will not be executed.

Loop Index:

Test Case inside loop can access the current loop index with the help of a special variable "$" (without double quotes). Loop index can be accessed in the following ways:

...

  1. First fetch data with the help of a REST API
    We are using Mock server to fetch data for our Update Contact API. You can extract test case data from any third party application with the help of a REST API.


    We have defined the mock server response in the following format:


    Now in Test Case's tab, fetch data using a separate test case as shown in snapshot below:


    Now extract the whole response with the help of special path "$". In the below snapshot, we have extracted the whole response in a variable named "data". We will use this variable as loop source.

  2. Create test case which is going to be part of loop
    We are creating test case for "Update Contact API" as shown in snapshot below. We will discuss the various properties of this test case later.
    Image Removed
    Image Added
  3. Setup loop construct
    Now select expand the test case and setup loop by simply providing data for field "Loop Source" in "Details" sub-tab of the test case.
    Image Removed
    Image RemovedDefine loop source 
    We  We are defining loop source to the variable which we extracted from mock server response as shown in snapshot below.
    Image RemovedImage Added

  4. Use loop source data in test case
    Loop index can be accessed using `$` symbol. Now we need to provide individual array item to the loop test case. We are providing the data to various properties of test case as shown in below snapshot.
    1. Request Body
      Image Removed
      Image Added

      Or you may define body parameters in Parameters tab as well, as shown in below snapshot:
      Image RemovedImage Added
    2. Assertions
      Image RemovedImage Added
    3. Expected Body
      Image RemovedImage Added
  5. Execution of test cases having loop constructs
    Now if we execute our test cases, then loop construct will be executed 5 times as array length was 5. In our sample demonstration, one iteration in the loop has failed. 
    Image RemovedImage Added 
  6. That's it. We request you to provide your feedback around this functionality.

...