Forum Discussion

baggiokdy's avatar
baggiokdy
New Contributor
7 years ago

Using text from Soap Request as parameters for queries

Hi All,

 

Relatively new to writing test cases in SOAPUI. Tearing my hair out trying to find a solution that fits the following.

I have a soap request from a system:

<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <Time>2018-03-01T12:35:25</Time>
      <Id>D1</Id>
      <EntityID>D1</EntityID>
      <Endpoint xsi:nil="true"/>
      <Sequence>1</Sequence>
      <Transport>TRANS</Transport>
      <Function>Hello</Function>
   </soap:Header>
   <soap:Body>
      <Status:Hello xmlns:StatusService="http://blah.com/service/statusservice">
         <Asset>
            <mID>123456</mID>
         </Asset>
         <Asset>
            <mID>1234567</mID>
         </Asset>
         <StatusContext>
            <clientID>http://blah/SOAP</clientID>
            <correlationID>D1</correlationID>
         </StatusContext>
      </StatusService:Hello>
   </soap:Body>
</soap:Envelope>

I have set my test item in SOAP UI to return a message received 0 success response which is all good.

I have an oracle database that contains a table ASSET with two columns 'mID' and 'Status'

I would like to use the values within the soap request 'mID', lookup the values within the ASSET oracle table then fill in a the following soap response for each:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:end="http://blah.com/callbackservice">
   <soapenv:Header/>
   <soapenv:Body>
      <end:ReceiveStatus>
         <CallbackContext/>
         <StatusRead>
            <status>$"Status from ASSET Oracle Tabale"</status>
            <Asset>
               <mID>$"mID from original request"</mID>
            </Asset>
         </StatusRead>
      </end:ReceiveStatus>
   </soapenv:Body>
</soapenv:Envelope>

 

Can't seem to find the correct solution.

 

Cheers 

2 Replies

  • StevenColon's avatar
    StevenColon
    SmartBear Alumni (Retired)

    Thank you for posting to our Community Forum. 

     

    You can use a Groovy Script TestStep to pull data from a Response and store it as a TestCase Property. 

     

    1. Add a Groovy Script TestStep after the Request TestStep
    2. Right-Click the editor and Select "Get-Data"
    3. Navigate to the Request TestStep and Select "ResponseAsXML"
    4. In the "Select XPath" tool, select the ID field

    ReadyAPI will generate a property expansion expression stored as a def. 

     

    In the next line, you need to store the value as a TestCase Property as shown here:

     

    context.testCase.setPropertyValue("Property Name", <Name of Def>)

    At this point, we now have a TestCase custom property that will be dynamically set to the xml fields value according to the Response. 

     

    In the subsequent JDBC TestStep, we can utilize the "Get Data" menu (if available) or write Property Expansion expressions to pull this TestCase property value to make dynamic queries. 

     

    Get Data Documentation: https://support.smartbear.com/readyapi/docs/testing/properties/get-data.html

    Property Expansion Documentation: https://support.smartbear.com/readyapi/docs/testing/properties/expansion.html

     

  • baggiokdy's avatar
    baggiokdy
    New Contributor

    Hi StevenJC,

     

    Thanks for the response.

     

    Apologies, forgot to mention that I am using SOAPUI 5.4.0 so do not have all the nifty tools from PRO. Is there a way of scripting the solution rather than using PRO utilities.

     

    Cheers