cancel
Showing results for 
Search instead for 
Did you mean: 

Getting array value from property transfer

SOLVED
Occasional Contributor

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?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super Contributor

Re: Getting array value from property transfer

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

 

View solution in original post

Highlighted
Occasional Contributor

Re: Getting array value from property transfer

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]

View solution in original post

3 REPLIES 3
Super Contributor

Re: Getting array value from property transfer

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

 

View solution in original post

Community Hero

Re: Getting array value from property transfer

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.


Regards,
Rao.
Highlighted
Occasional Contributor

Re: Getting array value from property transfer

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]

View solution in original post

New Here?
Join us and watch the welcome video:
Read the Latest News
NovemberNews
Top Kudoed Authors