Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property Transfer from a testcase response to a request in different testcase

Testing a rest service in SoapUI, I need to do a property transfer from a testcase response to a request in different test case.

JsonResponse in the first testcase is as follows:

     {[{
         "items":[{
         "id": "1234",
         "state": "XYZ",
         "type" : "ABCD"
     },
     {
         "id": "12345",
         "state": "XYZV",
         "type" : "ABCDF"
     }
  ]}

The id(just one) from the response has to be directed to the Json request of the second testcase via property transfer

    {
         workItemsId: ["1234"],
        field: "ABCD"
    }

I have tried using items[0].id, but that transfers only the value. I need it as an array in the response. Any help would be deeply appreciated. I am so new to SOAP-UI.

like image 555
Binoy Cherian Avatar asked Feb 19 '16 07:02

Binoy Cherian


2 Answers

IMO the easy way to do so is using the property expansion. For you case you can use the follow notation approach ${Test step name#Response#JSONPath}.

Supposing you have a first testStep named REST Test Request with the follow response:

{
    "items":[
        {"id": "1234","state": "XYZ","type" : "ABCD"},
        {"id": "12345","state": "XYZV","type" : "ABCDF"}
    ]
}

And you want to use the first id from items array in a second testStep request and setting it inside array you can use the follow notation:

{
    workItemsId: [${REST Test Request#Response#$items[0].id}],
    field: "ABCD"
}

UPDATE

If as you comment you want to use the JSONPath expression in a property transfer, add a Property transfer testStep, select as source your request, as property response, as path language JSONPath then put the expression $items[0].id and finally select the property where you want to put the result. Finally your property transfer will looks like:

enter image description here

Hope it helps,

like image 194
albciff Avatar answered Nov 19 '22 04:11

albciff


Are you using two test cases for this or just two test steps? Anyways, rather than transferring the property directly to next request, you can set it as a property on test case and then use that property in next request with property expansion. So,

  1. create a property "id" on test case.
  2. In property transfer step set the value of this property using items[0].id
  3. In next request use property expansion to populate the value, so json will look like:

    {
      workItemsId:["${#TestCase#id}"],
      field: "ABCD"
    }
    

Here are more details about property expansion : https://www.soapui.org/scripting---properties/property-expansion.html

like image 25
user3190129 Avatar answered Nov 19 '22 04:11

user3190129