SoapUI Open Source API request response chaining with JSON

Raghwendra Sonu
3 min readOct 8, 2019

--

There are two ways to do this.

1st way : Using Property Transfer step

Step 1 : Add the api requests in a test case

Request1: Add a GET request for below endpoint, this lists all the available users on page2.

https://reqres.in/api/users?page=2

Request2: Add another request of PUT type, this will update one of the user.

https://reqres.in/api/users/2

Request Body:

{
"name": "morpheus",
"job": "zion resident"
}

Step 2 : Add a property transfer step

Goto the first request in testcase -> right click -> Insert Step -> property transfer

Step 3 : Create a new property transfer, Provide source and target details

Source: ListUsers , property: Response, Path Language: JSONPathTarget: UpdateAUser, property: Request, Path Language: JSONPath

Goto http://jsonpathfinder.com/ or install Chrome extension : Json path finder, as we need to give XPATH for the the JSON element we want to retrieve.

In this case we are retrieving first_name of 6th user from ListUsers response and fetching that as name in the request of UpdateAUser.

Remember to provide JSON path for the Target as well, else it will replace the entire request with first_name value.

Step 5 : Run and check the results

2nd way : Using Groovy script, insert step -> Groovy Script. We will be using JsonSlurper. This is a class that parses JSON text or reader content into Groovy data structures (objects) such as maps, lists and primitive types like Integer, Double, Boolean and String.

The class comes with a bunch of overloaded parse methods plus some special methods such as parseText, parseFile and others. For the next example we will use the parseText method. It parses a JSON String and recursively converts it to a list or map of objects.

def resp = testRunner.testCase.getTestStepByName('ListUsers').getPropertyValue('response')
def jsonSlurper = new groovy.json.JsonSlurper()
def object = jsonSlurper.parseText(resp)
def value = object.data[5].first_name

Add a properties step in Test Steps. Create a new property user, keep value as empty.

Write the property value captured above in MyProperties file.

testRunner.testCase.getTestStepByName('MyProperties').setPropertyValue('user',value)

Run the groovy script, this will update user property in MyProperties file.

So now we are able to capture and store property value. One last thing is to use this in our UpdateAUser request. For this, update name in request body with parameter as below.

${MyProperties#user}

Run the UpdateAUser request and you will see, name getting updated accordingly.

This is how we do request and response mapping in Soap UI for JSON.

Hope this was helpful.

GIT code available here.

https://github.com/raghwendra-sonu/REST-Project-Property-Transfer-soapui-project

Let me know if this was helpful. If you ever need my help, you can write in comments sections. Also, you can contact me through my LinkedIn Profile.

--

--

Raghwendra Sonu
Raghwendra Sonu

Written by Raghwendra Sonu

Software Automation Testing expert with 9 years of work experience in diverse tools and technologies.

No responses yet