Web Service Scripting using the Web Services Protocol in LoadRunner VuGen:
This tutorial is an addendum to our VuGen scripting series, here we will learn to script in one of the most important protocols (other than Web-HTTP/HTML protocol) – ‘Web Services’.
To start with, let’s understand what is meant by Web Service? A Web Service is a piece of code (that can perform specific operation/operations) that is available on the internet and is the one which can communicate and serve data to the other applications or devices irrespective of their underlying architecture and technology.
In this modern era, a software system need not be built from scratch. There are many services that are readily available and one can call and use in his/her application.
For Example, if we want a payment gateway in our application, we need not build one – we can use (may need to pay) the services of any of the already established payment gateway providers.
The underlying principle behind the successful implementation of Web Services is the standard way of integration and communication (between applications) using open standards.
Web services are generally of two types:
- SOAP: SOAP stands for Simple Object Access Protocol and is an XML based industry standard protocol for designing and developing web services. As it is XML based, it is platform and language independent.
- REST: REST stands for Representational State Transfer and is an architectural style for developing web services. It’s getting popular because of its lightweight nature (consumes less bandwidth and resource in its implementation). It permits multiple data formats like JSON, Text, XML etc.
Now let’s see how to do SOAP Web service scripting using VuGen.
As already discussed, SOAP is an XML based protocol (it uses XML to send and receive messages). There is one more thing that we need to understand – WSDL. WSDL (Web Services Description Language) is an XML-based file that gives details like what the web service does along with the information required to access the web service.
For our Example script, we will use a currency converter Web Service.
This service provides the following operations (In general, a Web service can provide multiple operations):
For Example, we can invoke the ‘GetCultureInfo’ operation and see the response.
This will be the corresponding WSDL link.
So let’s start by creating a new (blank) VuGen script with ‘Web Services’ protocol.
Go to the ‘SOA Tools’ menu and select ‘Manage Services’.
On the ‘Manage Services’ window, click on ‘Import’ (to import a new service).
Select URL (or File) and click on ‘Import’.
Make sure the WSDL is imported successfully.
Now go to the ‘SOA Tools’ menu again and select ‘Add Service Call’.
On the ‘New Web Service Call’ window, we can see fields like ‘Service’, ‘Port Name’ and ‘Operation’.
Let’s select ‘GetCultureInfo’ operation here.
‘Transport Layer Configuration’ allows us to specify transport options (leave it to the default options).
‘Custom SOAP Header’ allows us to enter the custom headers if any (do not enter anything for now).
‘Input Arguments’ allow us to enter the data input required for this operation. For this operation, there is only one input required – Currency.
We can enter the input value directly or choose to select it from a parameter file. Let’s enter the value ‘USD’ for now.
‘Output Arguments’ allow us to enter a parameter name into which we want the response to be saved. Leave it to the default name and click on ‘OK’.
This will create the script as shown.
Let’s replay the script.
As shown below, the response of this Web service operation request is successfully received.
(Note: Click on below image for enlarged view).
We can do further enhancements to this script like adding transactions, correlations (using lr_xml_get_values function) and text verification (using lr_xml_find function). Please refer to function reference to understand how to use these functions.
Note: We can create VuGen script for Web Services using Web – HTTP/HTML protocol also. For this, we need to have the XML requests (and not the WSDL file only), we can then pass this XML request as a body to web_custom_request function in Web-HTTP/HTML protocol script.
So with ‘Web Services’ protocol scripting, we would have understood that scripting options and procedure changes with the protocol chosen.
However, it is recommended to explore and learn to script in other protocols (some of the important ones being a True client, Oracle NCA, SAP –Web/GUI, Citrix ICA etc.) to become perfect with VuGen.
In the next tutorial, we will learn VuGen script files and Runtime settings.