Forum Discussion

testingRocks's avatar
testingRocks
Occasional Contributor
7 years ago

How to iterate Properties value in request URI?

Hello,

I am using ReadyAPI. I have a json response from which I am able to fetch a value depending on its index-->write to Property-->Fetch from Property and pass to a URI.

I am able to do this only for one value but I have multiple different values with different indexes. How can I loop through all the values and pass them to the URI in the looping steps.

Any help/suggestions is appreciated.

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Please show how you have done for one.
    • testingRocks's avatar
      testingRocks
      Occasional Contributor

      1. To fetch and write to property step, I am using groovy:

      import groovy.json.*
      def api_response = context.expand( '${APIstep#Response}' ).toString()
      def json = new JsonSlurper().parseText (api_response);

      def MAX_LIMIT = 3
      def IDs = new Object[MAX_LIMIT]
      IDs[0] = id_1 = json.id[0].toString().replaceAll("[^a-zA-Z0-9 ]+","");
      IDs[1] = id_1 = json.id[1].toString().replaceAll("[^a-zA-Z0-9 ]+","");
      IDs[2] = d_1 = json.id[2].toString().replaceAll("[^a-zA-Z0-9 ]+","");


      int i=0;
      while (i<3)
      {
      if (i<3)
      {
      testRunner.testCase.getTestStepByName("Properties").setPropertyValue("testID",IDs[i]);
      log.info IDs[i]
      }
      i++;
      }

       

      2. Then I am passing that value from property to API2 URI using ${Properties#testID}

       

      These steps only keep the last id value. I added a datasource loop step in the end but it does not help either