It has been always a great experience for me to test web services. The way it extends the web infrastructure to provide the method/path to applications to connect to other applications is really interesting. Automating Web Services using QTP have always been easy and simple to use. HP Service Test and QTP Web Service Add-in are great solutions for Web Services Testing.I have written some posts on Web Services Testing using QTP earlier at LearnQTP. I hope you must have enjoyed and learned about it from there.
With the launch of UFT, HP has now removed web service add-in and combined HP Service Test with QTP, which is definitely going to give an entirely new direction to automate Web Services. However Web Service Add-in is not completely removed, but it has been made hidden into UFT. You can find the way to unhide it in our next post, stay tuned. In this post, We will see that how the things are different now for Web Services Testing in UFT. We will discuss and Create a SOAP Web Service Test.
I have already explained the important key points about web services in my older post, Still for your reference and convenience I will keep them here as well in brief. In a SOAP based web service testing, WSDL plays an important role. Web Services Description Language (WSDL) is an XML-based language for locating and describing Web services. Now as the Web Service is powered by the web application server that uses SOAP to understand and speak with web services and delivers information in XML. Simple Object Access Protocol (SOAP) is an XML based protocol to exchange information over HTTP. To locate the web services WSDL documents are indexed in searchable Universal, Description, Discovery and Integration (UDDI) business registries. Learn more about SOAP here.
The very first step to create a test in UFT is to Import the WSDL. We have API Test in UFT for such testing. We will be using the same example of the TempConvert web service provided by W3C. This web service has two methods ‘CelsiusToFahrenheit’ and ‘FahrenheitToCelsius’ and simply takes the temperature and converts it to the required.
Below is the WSDL for the Service. http://www.w3schools.com/webservices/tempconvert.asmx?WSDL To Create an API Test, Select File > New >Test >API Test and name the test. Click on Import WSDL on the UFT toolbar. This gives you two options –
- Import WSDL from URL or UDDI – Select this option to import WSDL from URL
- Import WSDL from File or ALM Application Component – Select this option, if you have the WSDL file or from ALM Component
In this example we will select Import WSDL from URL or UDDI and enter the wsdl url mentioned above (http://www.w3schools.com/webservices/tempconvert.asmx?WSDL) in the Address field and Select URL option and Click OK to proceed. UFT imports and read the methods and parameters of web service to work with. You can find all the methods or operations of web services at the ToolBox pane under Local Activities. In this case, you will find two operations under TempConvert Service as in the snapshot below. These operations can be used to test the web service. To use an operation to test, you just need to drag the operation from Local Activities area and drop onto the canvas area under test flow. Let’s say you drag FarenheitToCelsius method to the test flow. This method needs a parameter temperature value to be passed. You can find this under Properties Pane, Input/Checkpoints tab. Select Grid or Text view. Grid Shows Properties and parameters in tabular format and the most convenient one. Text view shows in XML format. The Input section in the Grid shows Envelope and Body section of the request XML.
Parameters for Requests can be found in the body section. In this case it is Farenheit. Enter Value of Farenheit, Save the test and that’s it. Your test is ready and can be executed now.
[fvplayer src=”http://automated-360.com/wp-content/uploads/2013/08/SOAPTestDragDrop_1.flv” autoplay=”true” embed=”false” loop=”true”]
Once Executed you get the result Pass or failure of service test, including the SOAP request and response details. These details also include the exact request sent and the response received.
That was pretty easy to use, isn’t it. Now lets say after importing the WSDL into UFT, we got some changes into the method or parameter. This leads us to update the WSDL we use in the test. UFT provides a feature to update the WSDL rather importing it again. We get two options here, either update from the same location or from a new location.
It is very simple to add checkpoint as well. To add a checkpoint for your test,
GOTO Properties Pane > Input/Checkpoint tab > checkpoint section.
Expand body section you will find the parameter FarenheitToCelcius, check the validate checkbox Slect the equal sign and enter the required value (77) re-run the test and you will find it validated in the result. We are getting this result as Failed as we entered wrong expected value in the checkpoint expected value.
This was just for the demonstration purpose, you need to enter the exact expected value accordingly. In the same way, we can test simple as well as complex operations of the web service easily using UFT. If you have got some more info about Web Service Testing using UFT or have any doubt or questions, let us know via the comments below.