Skip to end of metadata
Go to start of metadata

In this post, we are going to demonstrate, how you may use your data stored in excel files to perform data driven testing with the help of looping feature of vREST.

Here is the video tutorial for the same:

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. 

Icon

For providing data with the help of CSV file, you will need to install vutil module. vutil module converts this CSV file into JSON format via REST API. For more information, please read Fetch CSV data for data driven testing.


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.
  • No labels