Forum Discussion

fidzah's avatar
fidzah
Occasional Contributor
6 years ago

Getting array value from property transfer

Hi,

The response that I get is something like this:

 

{
   "OperationResultType": "Success",
   "Code": 0,
   "Message": "",
   "Details": "",
   "ResultValue":    {
      "Ids":       [
         "177",
         "178"
      ],
      "Errors":       [
         "",
         ""
      ]
   }
}

How do I get the array value of "Ids" transferred to next test case?

  • Hi Fidzah,

     

    There are 2 ways you can do it. Either you can write groovy script and store the values to the Properties Step.

     

    import groovy.json.JsonSlurper
    def json = '''{
    "OperationResultType": "Success", "Code": 0, "Message": "", "Details": "", "ResultValue": { "Ids": [ "177", "178" ], "Errors": [ "", "" ] } }''' def jsonSlurper = new JsonSlurper() def obj = jsonSlurper.parseText(json) log.info obj.ResultValue.Ids testRunner.testCase.getTestStepByName("Properties").setPropertyValue("ID", obj.ResultValue.Ids)

    Else you can use PropertyTransfer step to write the xpath for the json path :-

    $.ResultValue.Ids

    You can use this website for json path evaluator - JSONPath Evaluator

     

  • fidzah's avatar
    fidzah
    6 years ago

    Thanks, this can be work if using groovy script.

    But I just want to retrieve it from the project.

    What I did is:  

    1 created 2 IDs from Property Transfer:


    sendID - $.ResultValue.BackupJobIds[0]
    sendID2 - $.ResultValue.BackupJobIds[1]

     

    NOTE: at the bottom of the PropertyTransfer screen, tick
    Entitize transferred values(s) - as the original response giving the value [[123]], so I need to get it as [123]

  • avidCoder's avatar
    avidCoder
    Super Contributor

    Hi Fidzah,

     

    There are 2 ways you can do it. Either you can write groovy script and store the values to the Properties Step.

     

    import groovy.json.JsonSlurper
    def json = '''{
    "OperationResultType": "Success", "Code": 0, "Message": "", "Details": "", "ResultValue": { "Ids": [ "177", "178" ], "Errors": [ "", "" ] } }''' def jsonSlurper = new JsonSlurper() def obj = jsonSlurper.parseText(json) log.info obj.ResultValue.Ids testRunner.testCase.getTestStepByName("Properties").setPropertyValue("ID", obj.ResultValue.Ids)

    Else you can use PropertyTransfer step to write the xpath for the json path :-

    $.ResultValue.Ids

    You can use this website for json path evaluator - JSONPath Evaluator

     

    • fidzah's avatar
      fidzah
      Occasional Contributor

      Thanks, this can be work if using groovy script.

      But I just want to retrieve it from the project.

      What I did is:  

      1 created 2 IDs from Property Transfer:


      sendID - $.ResultValue.BackupJobIds[0]
      sendID2 - $.ResultValue.BackupJobIds[1]

       

      NOTE: at the bottom of the PropertyTransfer screen, tick
      Entitize transferred values(s) - as the original response giving the value [[123]], so I need to get it as [123]

  • nmrao's avatar
    nmrao
    Champion Level 3
    Each test case should be independent - is the best practice. Not sure of your use case to have dependency on other test case. Check if it is really needed that way ? Otherwise, redesign the tests.