Forum Discussion

Oct21's avatar
Oct21
Occasional Contributor
6 years ago

Property transfer from response of one request to another request

Hi 

Am new to Soap UI, Please help me in this.

I have to transfer response value of my response XML to another request XML.

Source response XML : 

<ReceiptId idOwner="ABC">
<IdValue name="ReceiptID">154068</IdValue>
</ReceiptId>

 

Target Request XML : 

<ReceiptId idOwner="ABC">
<IdValue name="ReceiptID">154068</IdValue>
</ReceiptId>

 

for which i am using property transfer but getting error.

RecieptID [net.sf.saxon.trans.XPathException: XPath syntax error at char 11 on line 2 in {\n//IdValue name=}:
Unexpected token name "name" beyond end of expression]

 

Waiting for early response.

 

Thanks,

Oct21

 

 

  • Thank you Oct21  for the response.

     

    First <CDATA> part needs to be extracted and then extract the value that is needed.

     

    Use below Script Assertion for the first soap request itself and no extra groovy script required.

     

    /**
    * Script Assertion for the first request
    * Extracts the required id value
    * and saves at test case level custom properties
    * which can be used later steps
    * where required
    **/
    
    assert context.response
    
    def getData = { data, element ->
       new XmlSlurper().parseText(data).'**'.find {it.name() == element}
    }
    
    def inXmlStr = getData(context.response, 'TA_RegisterCandidateForAssessmentResult').text()
    
    def receiptId = getData(inXmlStr, 'ReceiptId')
    context.testCase.setPropertyValue('ID', receiptId.IdValue.toString())

    In the next request, use ${#TestCase#ID} where the value is needed.

  • nmrao's avatar
    nmrao
    Champion Level 3
    It would be difficult to help with the provided information. Please specify full response of the 1st step.
    • Oct21's avatar
      Oct21
      Occasional Contributor

      Here is the response of the first request.

       

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <soap:Body>
      <TA_RegisterCandidateForAssessmentResponse xmlns="http://tempuri.org/">
      <TA_RegisterCandidateForAssessmentResult><![CDATA[<AssessmentOrderAcknowledgement xmlns="http://ns.hr-xml.org/2004-08-02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ns.hr-xml.org/2004-08-02 AssessmentOrderAcknowledgement.xsd">
      <ClientId idOwner="CEB">
      <IdValue name="CustomerId">2000488</IdValue>
      </ClientId>
      <ReceiptId idOwner="CEB">
      <IdValue name="ReceiptID">154196</IdValue>
      </ReceiptId>
      <ClientOrderId idOwner="Taleo">
      <IdValue name="OrderID">200484-OrderId</IdValue>
      </ClientOrderId>
      <AccessPoint>
      <InternetWebAddress>https://integration-talentcentral-qa2.eu.shl.com/integration/ce/ba5f35672a4140558e2195f188e2ad5d/?rid=154196</InternetWebAddress>
      </AccessPoint>
      <AssessmentStatus>
      <Status>Acknowledged</Status>
      <Details/>
      <StatusDate>2019-02-05</StatusDate>
      </AssessmentStatus>
      </AssessmentOrderAcknowledgement>]]></TA_RegisterCandidateForAssessmentResult>
      </TA_RegisterCandidateForAssessmentResponse>
      </soap:Body>
      </soap:Envelope>

       

      Regards,

      Oct21

      • nmrao's avatar
        nmrao
        Champion Level 3

        Thank you Oct21  for the response.

         

        First <CDATA> part needs to be extracted and then extract the value that is needed.

         

        Use below Script Assertion for the first soap request itself and no extra groovy script required.

         

        /**
        * Script Assertion for the first request
        * Extracts the required id value
        * and saves at test case level custom properties
        * which can be used later steps
        * where required
        **/
        
        assert context.response
        
        def getData = { data, element ->
           new XmlSlurper().parseText(data).'**'.find {it.name() == element}
        }
        
        def inXmlStr = getData(context.response, 'TA_RegisterCandidateForAssessmentResult').text()
        
        def receiptId = getData(inXmlStr, 'ReceiptId')
        context.testCase.setPropertyValue('ID', receiptId.IdValue.toString())

        In the next request, use ${#TestCase#ID} where the value is needed.

  • vijayk1's avatar
    vijayk1
    Occasional Contributor

    use groovy to parse request and save IdValue.

    then use ${#TestSuite#IdValue} in request xml.

     

    Hope below groovy code can work for you.

    import groovy.util.XmlSlurper

    response= testRunner.testCase.getTestStepByName("Source Request Name").getPropertyValue("Response")
    parsedResponse = new XmlSlurper().parseText(response)
    String IdValue=parsedResponse.ReceiptId.IdValue

    testRunner.testCase.testSuite.setPropertyValue("IdValue",IdValue)

     

    <ReceiptId idOwner="ABC">
    <IdValue name="ReceiptID">${#TestSuite#IdValue}</IdValue>
    </ReceiptId>

     

    Regards,

    Vijay

     

    • Oct21's avatar
      Oct21
      Occasional Contributor

      Thanks for the help!

      I have tried the groovy script, it created the custom property name idvalue but the value is not copied.

      Please see the screnshot and let me know where i am wrong.

       

      Regards,

      Oct21

       

      • vijayk1's avatar
        vijayk1
        Occasional Contributor

        Sorry I dont know how to parse Soap Envelope.

         

        But below code can work (i checked based on your soap response)

        import groovy.util.XmlSlurper

        response= testRunner.testCase.getTestStepByName("Source Request Name").getPropertyValue("Response")

        String parsedResponse = new XmlSlurper().parseText(response)
        String IdValue = parsedResponse.toString().substring(349,355)

         

         

        You can try changing substring range or work for better Soap XML parser

         

        Regards,

        Vijay