Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Current »

With the help of looping functionality, now you may execute multiple iterations of a test case. 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. 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.
  3. Once you submit the loop source then a loop indicator will appear on the header of the test case.

Loop Source:

Loop source can be any of the following:

  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. Boolean Value
    1. If the value is false then test case inside loop will not be executed.
    2. Otherwise test case inside loop will 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 loop source contains variable name (say {{data}}) which value is an array then individual array item can be accessed using $ as below:
    {{data.$.xyz}}

Usage Scenarios:

Data Driven Testing:

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 loop. And we are providing data to Update Contact API with the help of Mock server. 

Steps:

  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.

  3. Setup loop construct
    Now expand the test case and setup loop by simply providing data for field "Loop Source" in "Details" sub-tab of the test case. We are defining loop source to the variable which we extracted from mock server response as shown in snapshot below.


  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



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

Few Caveats:

  1. Request Method cannot be defined as dynamic for the loop test case.

  2. Different set of request query parameters for each iteration cannot be defined for the loop test case. However if you are using same set of query parameters then values can be dynamic for each iteration.
  3. Similarly different set of assertions cannot be defined for the loop test case. However if you are using same set of assertions then values can be dynamic for each iteration.

 

 

 

 

  • No labels