cancel
Showing results for 
Search instead for 
Did you mean: 

Property transfer from response of one request to another request

SOLVED
Highlighted
Occasional Contributor

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Property transfer from response of one request to another request

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.



Regards,
Rao.
9 REPLIES 9
Community Hero

Re: Property transfer from response of one request to another request

It would be difficult to help with the provided information. Please specify full response of the 1st step.


Regards,
Rao.
Occasional Contributor

Re: Property transfer from response of one request to another request

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

 

Occasional Contributor

Re: Property transfer from response of one request to another request

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/?ri...>
</AccessPoint>
<AssessmentStatus>
<Status>Acknowledged</Status>
<Details/>
<StatusDate>2019-02-05</StatusDate>
</AssessmentStatus>
</AssessmentOrderAcknowledgement>]]></TA_RegisterCandidateForAssessmentResult>
</TA_RegisterCandidateForAssessmentResponse>
</soap:Body>
</soap:Envelope>

 

Regards,

Oct21

Occasional Contributor

Re: Property transfer from response of one request to another request

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

 

Occasional Contributor

Re: Property transfer from response of one request to another request

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

Community Hero

Re: Property transfer from response of one request to another request

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.



Regards,
Rao.
Occasional Contributor

Re: Property transfer from response of one request to another request

Thanks this worked perfectly.. @nmrao 

Appreciate it !!

@vijayk1 Thanks for the help

 

Regards,

Oct21

Community Hero

Re: Property transfer from response of one request to another request

You should mark the reply which solved the issue as Solution, but not your thank you reply as solution. For now, I have changed that.


Regards,
Rao.
Community Hero

Re: Property transfer from response of one request to another request

@vijayk1,

One should not depend on the substring in this case as response content may vary.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Top Kudoed Authors