mkhan031486
8 years agoContributor
Saving a element from JDBC response as a property
Hi . In one of my tests in SoapUI, I have to run a JDBC query and then select an element from the response and save it as a property. All through groovy. I'm doing the following.
1- Response from JDBC query:
<RESULTS>
<RESULTSET fetchsize="10">
<ROW rownumber="1">
<PAYMENT_AMT>164.98</PAYMENT_AMT>
<PAYMENT_ID>445958</PAYMENT_ID>
</ROW>
</RESULTSET>
</RESULTS>
2- Therefore, I want to fetch that PAYMENT_ID and save it as a property through groovy. Below is the script that I'm using:
assert context.response, 'Response is empty or null'
def paymentId = new XmlSlurper().parseText(context.response).'**'.find{it.name() == 'PAYMENT_ID'}.text()
context.testCase.testSuite.setPropertyValue("TEST1_PAYMENT_ID", paymentId)
But after using the above script i'm seeing the following error message:
Response is empty or null. Expression: context.response
Can please somebody check and see why i'm receiving this error.
1- Response from JDBC query:
<RESULTS>
<RESULTSET fetchsize="10">
<ROW rownumber="1">
<PAYMENT_AMT>164.98</PAYMENT_AMT>
<PAYMENT_ID>445958</PAYMENT_ID>
</ROW>
</RESULTSET>
</RESULTS>
2- Therefore, I want to fetch that PAYMENT_ID and save it as a property through groovy. Below is the script that I'm using:
assert context.response, 'Response is empty or null'
def paymentId = new XmlSlurper().parseText(context.response).'**'.find{it.name() == 'PAYMENT_ID'}.text()
context.testCase.testSuite.setPropertyValue("TEST1_PAYMENT_ID", paymentId)
But after using the above script i'm seeing the following error message:
Response is empty or null. Expression: context.response
Can please somebody check and see why i'm receiving this error.
For JDBC request use context.responseAsXml. That is the property name on test step custom properties tab.