Karunagara Pandi
Karunagara Pandi

Reputation: 644

How to get response value from Currency Converter service response through groovy script in SoapUI?

I'm using Currency Converter webservice to practice groovy script in SoapUI Pro.

In that, I have created a property that should get response / output of the Currency Converter service through groovy script.

For that, I tried the following script which gets all the raw response data :(

I need to get the exact result i.e. converted value and assign to the property.

Can anyone provide me the correct groovy script?

Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:ConversionRate>
         <web:FromCurrency>USD</web:FromCurrency>
         <web:ToCurrency>INR</web:ToCurrency>
      </web:ConversionRate>
   </soapenv:Body>
</soapenv:Envelope>

Response:

<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>
      <ConversionRateResponse xmlns="http://www.webserviceX.NET/">
         <ConversionRateResult>60.54</ConversionRateResult>
      </ConversionRateResponse>
   </soap:Body>
</soap:Envelope>

Thanks
Karunagara Pandi

Upvotes: 0

Views: 1164

Answers (1)

SiKing
SiKing

Reputation: 10329

First you need access to the Response.

def conversionRateResult = context.expand( '${step_name#Response#//*:ConversionRateResult}' )

Then to assign it to a property depends on multiple things: 1) where are you doing it from, and 2) where do you want the property assigned.

To crawl the hierarchy from a script step, you would do something like:

testRunner.testCase.setPropertyValue("property_name", conversionRateResult)

Consider browsing through the documentation and API.

Upvotes: 1

Related Questions