Versions Compared

Key

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

...

With the help of looping functionality, now you may execute multiple iterations of a test case inside a loop. To setup a loop, please follow the steps below:

  1. First create a test case which you think, will be part of loop. Skip this step, if test case is already created.
  2. Then select the test case, which is going to be part of loop.
  3. Now select dropdown "1 Selected" from the test case's toolbar and then select operation "Setup Loop" as shown in image below:
    Image RemovedLoop construct will be created around the test case as shown in image below:
    Image Removed
    Note: The above loop will be executed only once because looping source is numeric `1`.

Looping Source:

...

  1. Simply go to Details sub-tab of this test case and provide value for loop source field. More information regarding loop source is provided below.
  2. Once you submit the loop source then a loop indicator will appear on the header of the test case.

    Image Added

Loop Source:

Loop source can be any of the following:

  1. Number Value
    If the looping source 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 Value
    1. If the looping source loop source is neither number nor variable then looping source loop source will be treated as boolean value.
      1. If the value is truthy then test case inside loop will 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. Using variable notation {{$}}. Wherever this variable is specified that will be replaced with the current loop index starting from zero.
  2. If the looping source loop source contains variable name (say {{data}}) which value is an array then individual array item can be accessed using $ as below:
    {{data.$.xyz}}

...

Context: We are defining test cases for a sample Contacts Application. More specifically we are validating various scenarios of Update Contact API with the help of loopingloop. And we are providing data to Update Contact API with the help of Mock server. 

...

  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 looping sourceloop 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.

  3. Setup loop construct
    Now select the test case and setup loop for the test case.


  4. Define looping source loop source 
    We are defining looping source loop source to the variable which we extracted from mock server response as shown in snapshot below.

  5. 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



      Or you may define body parameters in Parameters tab as well, as shown in below snapshot:
    2. Assertions
    3. Expected Body
  6. 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. 
     
  7. That's it. We request you to provide your feedback around this functionality.

...