************************本文非原创 **************
Some time ago I described how to test web services in LoadRunner with HTTP/HTML script. Right now I would like to describe the correct way – testing with Web Services script.
First of all we need a web services. And there is one available exactly for training. Here is the WSDL http://soatest.parasoft.com/store-01.wsdl. I hope that folks from Parasoft don’t mind we are not using SOATest
In any case, we have an WSDL file. Now lets create new script.
Click File / New and select “Web Services” from list of available scripts types.
Now, when we have new script. we should see new toolbar under the standard one. It allows to add Web Services description to the script. (from WSDL file), add XML request using form. and add XML request from file. So lets click on “Manage Services” button and then “Import”. Enter WSDL url http://soatest.parasoft.com/store-01.wsdl and click “Import”.
After WSDL file is imported, just click “Apply” and “OK”. From this point LoadRunner has description of our web services so we can use it send some requests. We will actually create two requests. One using “Add Service Call” and second using “Import SOAP” buttons from toolbar.
Click on “Add Service Call”. In “Operation” dropdown list select value “getItemById”. On left side select “id” under Input Arguments tree node. Then on right side type “1″ into Value editbox.
Now our script. should look like this:
Action()
{
web_service_call("StepName=getItemById_101",
"SOAPMethod=Cart|ICart|getItemById",
"ResponseParam=response",
"Service=Cart",
"ExpectedResponse=SoapResult",
"Snapshot=t1248415874.inf",
BEGIN_ARGUMENTS,
"id=1",
END_ARGUMENTS,
BEGIN_RESULT,
END_RESULT,
LAST);
return0;
}
Now lets add Web Service request using Import SOAP. Lets assume we have XML request saved in file on the disk. Here is an example:
<?xmlversion="1.0"encoding="UTF-8"?>
<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<getItemByTitlexmlns="http://www.parasoft.com/wsdl/store-01/">
<titleKeyword>Linux</titleKeyword> </getItemByTitle>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Click “Import SOAP” button and select your file. Change type from “Web Service Call (Recommended)” to “SOAP Request”. Select URL from the list, and type into SOAPAction this value “getItemByTitle”. Click OK.
Now we’ve added second call that ask for book details for title “Linux”. Our script. should look like this:
Action()
{
web_service_call( "StepName=getItemById_101",
"SOAPMethod=Cart|ICart|getItemById",
"ResponseParam=response",
"Service=Cart",
"ExpectedResponse=SoapResult",
"Snapshot=t1248415874.inf",
BEGIN_ARGUMENTS,
"id=1",
END_ARGUMENTS,
BEGIN_RESULT,
END_RESULT,
LAST);
soap_request("StepName=SOAP Request",
"URL=http://ws1.parasoft.com/glue/store-01",
"SOAPEnvelope="
"<?xmlversion=\"1.0\"encoding=\"UTF-8\"?>"
"<SOAP-ENV:Envelopexmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
"<SOAP-ENV:Body>"
"<getItemByTitlexmlns=\"http://www.parasoft.com/wsdl/store-01/\">"
"<titleKeyword>Linux</titleKeyword>"
"</getItemByTitle>"
"</SOAP-ENV:Body>"
"</SOAP-ENV:Envelope>",
"SOAPAction=getItemByTitle",
"ResponseParam=response",
"Snapshot=t1248416271.inf",
LAST);
return 0;
}
As you can see, each request contain “ResponseParam=response”. LoadRunner will automatically save response XML into parameter with name “response”. We can easily display this parameter by addind
lr_message(lr_eval_string("Response XML is\n{response}"));
after each call. So at the end out script. should look like this:
Action()
{
web_service_call( "StepName=getItemById_101",
"SOAPMethod=Cart|ICart|getItemById",
"ResponseParam=response",
"Service=Cart",
"ExpectedResponse=SoapResult",
"Snapshot=t1248415874.inf",
BEGIN_ARGUMENTS,
"id=1",
END_ARGUMENTS,
BEGIN_RESULT,
END_RESULT,
LAST);
lr_message(lr_eval_string("Response XML is \n{response}"));
soap_request("StepName=SOAP Request",
"URL=http://ws1.parasoft.com/glue/store-01",
"SOAPEnvelope="
"<?xmlversion=\"1.0\"encoding=\"UTF-8\"?>"
"<SOAP-ENV:Envelopexmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
"<SOAP-ENV:Body>"
"<getItemByTitlexmlns=\"http://www.parasoft.com/wsdl/store-01/\">"
"<titleKeyword>Linux</titleKeyword>"
"</getItemByTitle>"
"</SOAP-ENV:Body>"
"</SOAP-ENV:Envelope>",
"SOAPAction=getItemByTitle",
"ResponseParam=response",
"Snapshot=t1248416271.inf",
LAST);
lr_message(lr_eval_string("Response XML is \n{response}"));
return 0;
}
At the end lets run our script. Output should be something like this: