Tags

, , , , , , , ,

Maybe for people who regularly use SoapUI to test web services, this topic is basic, but for me it was a chalenge. So now, I will explain you this little trick that SoapUI has in store for you.

The project- Countries info

The project is a simple web service that retrieves currency and country information. The WSDL for this service can be found here: http://www.webservicex.net/country.asmx?WSDL .So, when we explore this nifty service we see that it has interesting request like getting the country’s currency. Let’s check it, shall we?

As we see, the info is correct, but it is contained in a CDATA XML element. This element has within it another XML, but the outer XML doesn’t see it that way- it’s just data for it. So, when we want to transfer an element from it, we can’t use the standart XPath. Here is a clever and easy workaround to this problem.

Transfering element within CDATA with a temporary property

For the example, we’ll create a Test case containing two requests: “GetCurrencyByCountry” and “GetCountryByCurrencyCode”. Between them, we will create a property transfer to get from the first request’s response the currency’s code and put it in the request parameter for the second. As response to the second request, we should get the country from the first one.
Now, to get the currency code returned by the first request and transfer it to the second we will create a temporary property in the Test case called CurrencyCode_temp.

In the transfer, we will create two transfer conditions. The first will get from the ready GetCurrencyByCountry request the CDATA and put it in the property CurrencyCode_temp.

After executing the first transfer condition, we create the second. The second will get from the property the currency’s code and transfer it to the second request.

Note: If you have SoapUI Pro, you cannot select the Xpath from the “Select Source XPath” window until you execute the first transfer.

And so, we have successfully transferred the property from within the CDATA in the XML response. Have fun testing your web services with SoapUI 🙂

Bonus

Since I am on the topic of SoapUI, I want to show you another trick. When you have a property in a test case and you want to access it from an assertion for instance, you can do that by using the following syntax:
${#TestCase#CurrencyCode_temp}
Please note that the first word is a keyword(‘TestCase’) and not the name of the test case, and the second is the property name. For more info, visit the SoapUI help for Property Expansion: link

Advertisements