Forum Discussion

mkhan031486's avatar
mkhan031486
Contributor
8 years ago

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:
&nbsp;
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:
&nbsp;
Response is empty or null. Expression: context.response
Can please somebody check and see why i'm receiving this error.&nbsp;
  • PaulMS's avatar
    PaulMS
    8 years ago

    For JDBC request use context.responseAsXml. That is the property name on test step custom properties tab.

  • nmrao's avatar
    nmrao
    Champion Level 3
    Use the above script as Script Assertion.
    • mkhan031486's avatar
      mkhan031486
      Contributor
      I'm doing that and I'm getting the error message that I have mentioned above. Do you think is there something wrong with my script?
      • PaulMS's avatar
        PaulMS
        Super Contributor

        For JDBC request use context.responseAsXml. That is the property name on test step custom properties tab.