cancel
Showing results for 
Search instead for 
Did you mean: 

Property transfer - transfer only part of the response

atlas
New Contributor

Property transfer - transfer only part of the response

Hi,

I am new to SoapUI webservices testing and I have problem with property transfer.

I am using http://www.webservicex.net/country.asmx?WSDL

 

I have created test case with 3 steps:

1. step is request GetCountryByCountryCode

2. step is property transfer

3. step is request: GetCurrencyByCountry

 

I want to use response of request 1 as input in request 2 (GetCurrencyByCountry) but the problem is that the response of the Req1 is the table like this:

 

<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>
<GetCountryByCountryCodeResponse xmlns="http://www.webserviceX.NET">
<GetCountryByCountryCodeResult><![CDATA[<NewDataSet>
<Table>
<countrycode>uk</countrycode>
<name>United Kingdom</name>
</Table>
<Table>
<countrycode>uk</countrycode>
<name>United Kingdom</name>
</Table>
</NewDataSet>]]></GetCountryByCountryCodeResult>
</GetCountryByCountryCodeResponse>
</soap:Body>
</soap:Envelope>

 

And I need to use/transfer only node <name>United Kingdom</name> to the second request input.

 

How can I define this in Property transfer source/target XPath?

 

Thank you.

5 REPLIES 5
nmrao
Community Hero

Re: Property transfer - transfer only part of the response

There are two names with United Kingdom, how do you decide which one to extract it first, later it can be transfered which is secondary.


Regards,
Rao.
atlas
New Contributor

Re: Property transfer - transfer only part of the response

Let's say I want to trasnsfer the first node with name :United Kingdom. So how will I define this in Property trasnfer XPath?

nmrao
Community Hero

Re: Property transfer - transfer only part of the response

Usually, one should be able to do it using xpath.

But your case is that data is wrapped inside CDATA which is treated as string not xml.

To do this, first cdata has to be extracted and converted it to xml to get the name you looking for?
By the way, do you get the same number of Table elements or there is possibility to get more or none as well in the result?


Regards,
Rao.
atlas
New Contributor

Re: Property transfer - transfer only part of the response

I get the same number of table elements for any request input (for any CountryCode).

 

Do you know, how can cdata be extracted and converted it to xml?

nmrao
Community Hero

Re: Property transfer - transfer only part of the response

IMO, this is case does not suit for using Property Transfer step because of cdata or atleast I am not aware to get the value using PT Step. So, alternative is to use Script Assertion.

 

Add a script assertion to the first test step, and add the below code in it. Also disable or remove(step 2 property transfer becomes obselete in this case)

 

Script Assertion code:

 

 

 

/**
* Below script extract the name from the first Table and
* set its value into a test case level custom property called
* COUNTRY_NAME
**/
def holder = new XmlHolder(messageExchange.response.responseContent )
def countryCodeResult = holder.getNodeValue('//*:GetCountryByCountryCodeResult')
log.info countryCodeResult
def cdataHolder = new XmlHolder(countryCodeResult)
def countryName = cdataHolder.getNodeValue("//Table[1]/name")
assert countryName, "Country name is empty or null"
context.testCase.setProperty('COUNTRY_NAME', countryName)

 And in the next request where the country name is needed use ${#TestCase#COUNTRY_NAME} 



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