Creating Web Services Script in LoadRunner using WebService/Web(http/html) Protocol
Some Important Definitions:
Types of Services:
We have mainly four types of Web Services XML-RPC, UDDI, SOAP and REST. See the details explanation in this link which is very helpful
Example 1:
Your company will have different branches like Online Order, Delivery and Pickup.
While doing online order you want to use Delivery service, so you are indirectly using Delivery service.
Delivery Service team gives you details about their service and you call that service every time you want Delivery.
Is delivery team did the performance test for that service,
How many concurrent calls it supports? What is the response time SLA for that service?
Which protocol works Best for Web Services Load test?
Before handing over to other people Delivery Service team has to do performance test and see how fast their service responds and how many concurrent calls it supports.
The Performance Test Goal of any web service is Concurrent Calls and Response time.
Performance testing Goals for Web Service
What Questions do you ask to Developer, Project Manager or Business Analyst Before Starting Performance Test?
Answer: How many concurrent calls this service has to support in production?
Developer Answer Example: My service should load in 0.5 sec with 100 concurrent calls.
How many concurrent users that you need to use?
Answer: It depends on the service responding, you need to adjust your concurrent users in such a way that you meet your 100 concurrent calls.
Web Services:
It is a web application components which can be published & used on web.
Web services do not require the use of browsers or HTML.
In Web Service XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for describing the services available and UDDI is used for listing what services are available.
XML: EXtensive Markup Language
XML is designed to describe the data & act as a tool for carrying information.
SOAP: Simple Object Access Protocol
It is a protocol for accessing web services.
Soap is a format for sending messages & used for communication between applications.
WSDL: Web Services description Language
It is an XML document which is used to describe & locate web services.
It specifies the location of the service and the operations (or methods).
Data requirements:
- Sample Request & Response XML.
- End Point URL(Host) where request xml to be posted. E.ghttp://webservice.nam.nsroot.net/
- WSDLfile to get the information & soap action for all the existing operations/methods.
- Operation details which needs to be invoked like “GetLoadDetails”.
- SSL Certificate(also known as a Web Server Certificate, Secure Server Certificate, and Digital Certificate) & password if the host is SSL secured.
Two different ways of creating Web Services Script:
We can do web services scripting in two ways:
- By using Web Services Protocol.
- By using Web(HTTP/HTML) Protocol.
Steps for writing script:
- Open the Vugen and select Web Services protocol.
- Click on Import SOAP on top navigation bar and select request xml file.
- Click LOAD and provide End Point URL(Host) & Soap action then press OK.
- Soap request will be created with the step name “SOAP Request”.
Error Handling & Validation:
lr_xml_find and lr_xml_get_values functions can be used to validate the page. If-Else statement can be used to validate the response.
Example:
lr_xml_find("XML={response}", "Query=//SOAP-ENV:Body/*/LoanAmount", "Value=2000", LAST );
lr_xml_get_values("Xml={response}", "Query=//SOAP-ENV:Header/*/UUID", "ValueParam=UUID", LAST);
Error Handling:
if (strcmp(lr_eval_string("{Response}"), "0") != 0 ) {lr_end_transaction (“Submit_Request", LR_FAIL);
LR_EXIT_ITERATION_AND_CONTINUE; lr_error_message(“Invalid Response"));
return 0;
} else {
lr_end_transaction ("Submit_Request ", LR_PASS);
}
Writing Script in Web(http/html) protocol:
We need to create Custom request using Web protocol & keep the xml request in the web request body.
Example:
web_custom_request("Weather SOAP Request",
"URL=http://www.webservice.nam.nsroot.net/GetLoanDetails",
"Method=POST",
"TargetFrame=",
"Resource=0",
"RecContentType=text/xml",
"Referer=",
"Mode=HTML",
"EncType=text/xml;charset=utf-8",
"Body=<<Your Complete XML Request>>", LAST);
We can capture complete response or any particular value using web_reg_save_param function.
Check point can also be added using web_reg_find function.
If-Else statement can be used for error handling check.
Examples:
web_reg_find("Text/IC=ResponseCode>0<",LAST);
web_reg_save_param(“Complete_Response",
"LB=",
"RB=",
"NOTFOUND=warning",
"SEARCH=ALL",
"ORD=1",
LAST );
Sample Script
Action()
{
web_service_call( "StepName=SayHello_101",
"SOAPMethod=HelloEndpointService|HelloEndpointPort|SayHello",
"ResponseParam=response",
"Service=HelloEndpointService",
"ExpectedResponse=SoapResult",
"Snapshot=t1579581442.inf",
BEGIN_ARGUMENTS,
"xml:HelloRequest="
"<HelloRequest>"
"<Name>Vijay</Name>"
"</HelloRequest>",
END_ARGUMENTS,
BEGIN_RESULT,
END_RESULT,
LAST);
lr_xml_find("Xml={SayHello_101_Response}", "Value=Hello Vijay!",
"Query=/SayHello/HelloResponse/Message/text()", LAST);
lr_xml_find("Xml={response}", "Value=Hello Vijay!",
"Query=/soap:Envelope[1]/soap:Body[1]/*[local-name()='SayHelloResponse'][1]/*[local-name()='HelloResponse'][1]/*[local-name()='Message'][1]/text()[1]", LAST);
lr_xml_get_values("XML={SayHello_101_Response}",
"ValueParam=MyName",
"Query=/SayHello/HelloResponse/Message/text()", LAST );
lr_output_message(lr_eval_string("Print my Name = {MyName}"));
return 0;
}
How do you do Text Check in Web Services or Capture Values
You will use lr_xml_find function or lr_xml_get_values function to do validate the response and capture the values.
Correlation in Web Service Protocol
To correlate any values in xml you need to use lr_xml_get_values
Scripting Using Web Protocol Web
You can use the web protocol the following way and you can use web_reg_save_param function to correlate the values.
web_set_sockets_option(“SSL_VERSION”, “TLS1.2”);
web_add_auto_header(“Sec-Fetch-Mode”, “navigate”);
web_add_header(“Sec-Fetch-User”, “?1”);
web_add_header(“Upgrade-Insecure-Requests”, “1”);
web_url("users",
"URL=https://go.co.in/pubapi/user_format=json&accesstoken=DHn67whALOdYMhP93kyp71lSFs7NREp",
"Resource=0",
"RecContentType=application/json",
"Referer=",
"Snapshot=t7.inf",
"Mode=HTML",
LAST);
===========
to extract response data
web_rest("GET: donuts.js",
"URL=http://adobe.github.io/Spry/data/json/donuts.js",
"Method=GET",
"Snapshot=t769333.inf",
LAST);
No comments:
Post a Comment