Marwa Abdelgawad Marwa Abdelgawad - 1 month ago 7
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="http://schemas.xmlsoap.org/soap/envelope/">
<NS1:Body>
<NS2:processRequestResponse xmlns:NS2="http://bussinessfacade.fawryswitch.ebpp.fawryis.com/">
<return>
<Response>
<SignonRs>
<ClientDt>2016-04-19T16:58:12.141</ClientDt>
<CustLangPref>ar-eg</CustLangPref>
<ServerDt>2016-11-02T13:58:09</ServerDt>
<Language>en-gb</Language>
<SignonProfile>
<Sender>FAWRY</Sender>
<Receiver>FAWRYRTL</Receiver>
<MsgCode>BillInqRs</MsgCode>
<Version>V1.0</Version>
</SignonProfile>
</SignonRs>
<PresSvcRs>
<RqUID>0045d98c-e81c-43fd-b887-b0b1a1b1641d</RqUID>
<AsyncRqUID>1a50b367-4aca-4d90-9f95-ddca99e8639d</AsyncRqUID>
<MsgRqHdr>
<NetworkTrnInfo>
<OriginatorCode>FAWRYRTL</OriginatorCode>
<TerminalId>11427</TerminalId>
</NetworkTrnInfo>
</MsgRqHdr>
<Status>
<StatusCode>200</StatusCode>
<Severity>Info</Severity>
<StatusDesc>Success.</StatusDesc>
</Status>
<BillInqRs>
<DeliveryMethod>POS</DeliveryMethod>
<BillRec>
<BillingAcct>0120000200</BillingAcct>
<BillTypeCode>111</BillTypeCode>
<BillRefNumber>2feeccae-8fd2-4d41-903a-df2ef96d5264</BillRefNumber>
<BillInfo>
<BillSummAmt>
<BillSummAmtCode>TotalAmtDue</BillSummAmtCode>
<CurAmt>
<Amt>370</Amt>
<CurCode>EGP</CurCode>
</CurAmt>
</BillSummAmt>
<IssueDt>2016-08-01</IssueDt>
</BillInfo>
</BillRec>
</BillInqRs>
</PresSvcRs>
</Response>
</return>
</NS2:processRequestResponse>
</NS1:Body>
</NS1:Envelope>





ack.imgur.com/Z7UwT.png

Rao Rao
Answer

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 { it.name() == 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')
log.info "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')
log.info "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>
Comments