Forum Discussion

rthupakula's avatar
rthupakula
New Contributor
13 years ago

Property Transfer : Unable to write XPath for SOAP Response

Hi Friends,

I'm using SOAPUI for testing of SOAP based web services.
My current task is as follows. I created a Project, TestSuite and one TestCase in it with the following Test Steps:

1. Test Step1 which makes a request to a service (Returns list of cities in that country) : SOAP REQUEST
input: Takes country name as input
output: Returns list of cities in that country as SOAP RESPONSE

2. Test Step 2 - Property Transfer : It collects one specified city name from response of Test Step1 and passes that value as input to Test Step3.
3. Test Step 3 - Will make a service call to another service (Weather Report of a city) : SOAP REQUEST
input : collects a parameter from Test Step2 (one city name)
output : Returns the weather report of that city (SOAP RESPONSE)

Issue: I'm unable to write a proper XPath expression to enter in the "SOURCE" and "DESTINATION". I need your help to write proper XPath expression for the SOAP RESPONSE AND SOAP REQUEST.

Bootom Line: Please provide the XPath SOURCE and DESTINATION for the Property Transfer created value.


MORE DETAILS:
.............................

Please find the Test Case - Test Steps below:

TEST STEP 1 # ############## (WSDL is : http://www.webservicex.net/globalweather.asmx?WSDL )
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
<soapenv:Header/>
<soapenv:Body>
<web:GetCitiesByCountry>
<!--Optional:-->
<web:CountryName>CANADA</web:CountryName>
</web:GetCitiesByCountry>
</soapenv:Body>
</soapenv:Envelope>

TEST STEP 2 ###############################
Created a Property Transfer to the test case - (The script for SOURCE AND DESTINATION is what I need).

I need to capture the value of a city ("Halifax International Airport") from the Response output and assign it as input to TEST STEP 3

I wrote a couple of XPath scripts which didn't work.

TEST STEP 3 #################################(WSDL is : http://www.webservicex.net/globalweather.asmx?WSDL )
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
<soapenv:Header/>
<soapenv:Body>
<web:GetWeather>
<!--Optional:-->
<web:CityName></web:CityName> <!-- This is the node which is needs the input from the Property Transfer -->
<!--Optional:-->
<web:CountryName>CANADA</web:CountryName>
</web:GetWeather>
</soapenv:Body>
</soapenv:Envelope>

3 Replies

  • You can delete your property transfer step and use property expansion.

    Since you didn't show your reponse to request 1 I will have to make one up.

    Place this property expansion directly in your GetWeather request:
    ${GetCitiesByCountry#response#//ns1:Item[1]/n1:City[1]/text()}

    Change this Xpath to the response that gets the cityname: //ns1:Item[1]/n1:City[1]/text()

    Here is more details on property expansion:
    http://www.soapui.org/Scripting-Propert ... nsion.html
  • Aaronliu's avatar
    Aaronliu
    Frequent Contributor
    Get Place Name from Response:
    declare namespace ns1='http://www.webservicex.net';
    //ns1:GetCitiesByCountryResponse[1]/ns1:GetCitiesByCountryResult[1]


    Transfer the Place Name to downline step as Request:
    declare namespace web='http://www.webservicex.net';
    //web:GetWeather[1]/web:CityName


    Or maybe you can use script assertion for it:

    def tc=testRunner.testSuite.testCase
    def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
    def holder=groovyUtils.getXmlHolder(messageExchange.responseContent)
    holder.namespaces['ns1']="http://www.webservicex.net"
    def CityName=holder.getNodeValue("//ns1:GetCitiesByCountryResponse[1]/ns1:GetCitiesByCountryResult[1]")
    tc.setPropertyValue("CityName",CityName)


    in step3, we manipulate value with parameters like: ${#TestCase#CityName}

    thanks,
    Aaron
  • Just one observation, Currently(25th Oct 2011) this services are providing not a Valid XML format. I feel there is a challenge in trying these solutions. Please find below response code for 'GetWeather' Service.
    Can any one check it out and provide a workaround for this,

    Thank you -

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <GetWeatherResponse xmlns="http://www.webserviceX.NET">
    <GetWeatherResult><![CDATA[<?xml version="1.0" encoding="utf-16"?>
    <CurrentWeather>
    <Location>Masindi, Uganda (HUMI) 01-41N 031-43E 1147M</Location>
    <Time>Oct 24, 2011 - 08:00 AM EDT / 2011.10.24 1200 UTC</Time>
    <Wind> from the SSE (160 degrees) at 9 MPH (8 KT):0</Wind>
    <Visibility> greater than 7 mile(s):0</Visibility>
    <Temperature> 73 F (23 C)</Temperature>
    <DewPoint> 64 F (18 C)</DewPoint>
    <RelativeHumidity> 73%</RelativeHumidity>
    <Status>Success</Status>
    </CurrentWeather>]]></GetWeatherResult>
    </GetWeatherResponse>
    </soap:Body>
    </soap:Envelope>