Marwa Abdelgawad Marwa Abdelgawad - 1 year ago 96
Groovy Question

Properties transfer in soapui using groovy

enter image description hereIs there any way that i can use groovy script to transfer values of properties from soap test case response to another soap test step? please find the response structure

<NS1:Envelope xmlns:NS1="">
<NS2:processRequestResponse xmlns:NS2="">

Rao Rao
Answer Source

You can use the Script Assertion for the same request step where the response is received. Can be avoided using separate Groovy Script step. So that check for the required values from the response before saving them as properties.

Script Assertion:

* This is script assertion
* retrieves specified values from currest step response
* and stores at test case level

//Closure to search the data
def searchData = { data, item ->
    data?.'**'.find { == item} as String
//Assert the response.
assert context.response, "Response is empty or null"

def parsedData = new XmlSlurper().parseText(context.response)

//Get Amount
def amt = searchData(parsedData, 'Amt') "Amount from response: ${amt}"
//Check the value amt
assert amt, "Amount is empty or not present"
//Store Amount at test case level
context.testCase.setPropertyValue('AMOUNT', amt)

//Get AsyncRqUID
def rqUid = searchData(parsedData, 'AsyncRqUID') "AsyncRqUID from response: ${rqUid}"
//Check the value rqUid
assert rqUid, "AsyncRqUID is empty or not present"
//Store RqUid at test case level
context.testCase.setPropertyValue('AsyncRqUID', rqUid)

The above would fetch values 370 as amount and 1a50b367-4aca-4d90-9f95-ddca99e8639d as AsyncRqUID.

In the other test request steps where you would require those retrieved values, please use as given below:

  • For Amount (Amt), ${#TestCase#AMOUNT}. Example <amount>${#TestCase#AMOUNT}</amount>
  • For RqUID, ${#TestCase#AsyncRqUID}. Example <rquid>${#TestCase#AsyncRqUID}</rquid>