用LoadRunner测试Web Services 协议.docx
- 文档编号:7879116
- 上传时间:2023-01-26
- 格式:DOCX
- 页数:11
- 大小:130.50KB
用LoadRunner测试Web Services 协议.docx
《用LoadRunner测试Web Services 协议.docx》由会员分享,可在线阅读,更多相关《用LoadRunner测试Web Services 协议.docx(11页珍藏版)》请在冰豆网上搜索。
用LoadRunner测试WebServices协议
URL:
...ting-in-loadrunner/
译者:
huiguiziran111 原作者:
Waldemar
前不久,如何用Loadrunner做webservices测试http/html脚本。
现在我想要描述的正确方法-用WebServices测试脚本。
首先需要一个webservices网址,并且是可以使用的网址。
这是一个WSDL的地址:
我希望Parasoft不要介意我使用的SOAT测试。
另外,我们要有一份WSDL文件。
现在让我们创造的脚本。
点击新建/从脚本协议中选择‘WebServices’脚本类型
现在,当我们新建一个脚本,都会产生一个新的标准的工具栏。
他允许添加webservice中描述的脚本文件,可以显示xml请求数据和返回的数据。
所以点击‘管理服务’,接着‘导入’,在URL中输入点击‘导入’
接着WSDL文件已经导入,直接点击‘应用’和‘确定’。
在这里Loadrunner把webservice引用的参数全部列举。
我们准备创建2个实际请求数。
在工具栏中,实现2个操作,一个是“增加呼叫服务”,另外一个是’导出SOAP’
点击‘AddServiceCall’。
在‘Operation’的下拉列表中选择‘getItemById’,在左边的输入参数列表中选择‘ID’然后在右边的类型的编辑框中输入‘1’
我们的脚本如下所示:
1. Action()
2. {
3. web_service_call("StepName=getItemById_101",
4. "SOAPMethod=Cart|ICart|getItemById",
5. "ResponseParam=response",
6. "Service=Cart",
7. "ExpectedResponse=SoapResult",
8. "Snapshot=t1248415874.inf",
9. BEGIN_ARGUMENTS,
10. "id=1",
11. END_ARGUMENTS,
12. BEGIN_RESULT,
13. END_RESULT,
14. LAST);
15. return0;
16. }
现在我们增加一个webservice请求导入SOAP中。
我们假定我们已经在XML文件的保存在磁盘中。
下面是一个例子:
xmlversion="1.0"encoding="UTF-8"?
>
1. 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"> 2. Body> 3. 4. 5. 6. Body> 7.
Envelope>
点击“导入SOAP”按钮和选择你的文件。
在’WebServiceCall(Recommended)’中更改“SOAPRequest”的类型。
在清单中选择URL和输入SOAP路径的值为“getItemByTitle”。
选择‘OK’我们添加第二次请求叫做Linux的详细说明书。
在我们的脚本如下所示:
1. Action()
2. {
3. web_service_call("StepName=getItemById_101",
4. "SOAPMethod=Cart|ICart|getItemById",
5. "ResponseParam=response",
6. "Service=Cart",
7. "ExpectedResponse=SoapResult",
8. "Snapshot=t1248415874.inf",
9. BEGIN_ARGUMENTS,
10. "id=1",
11. END_ARGUMENTS,
12. BEGIN_RESULT,
13. END_RESULT,
14. LAST);
15. soap_request("StepName=SOAPRequest",
16. "URL=
17. "SOAPEnvelope="
18. "
xmlversion=\"1.0\"encoding=\"UTF-8\"?
>"
19. " 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\">" 20. " Body>" 21. " 22. " 23. "" 24. " Body>" 25. "
Envelope>",
26. "SOAPAction=getItemByTitle",
27. "ResponseParam=response",
28. "Snapshot=t1248416271.inf",
29. LAST);
30. return0;
31. }
正如你所见的,每个请求都包含在“ResponseParam=response”,LoadRunner将会自动保存返回到XMl的参数化到表’repose’。
我们可以得到显示该参数化返回的结果。
最后,脚本应该就如下所示:
1. lr_message(lr_eval_string("ResponseXMLis\n{response}"));
1. Action()
2. {
3. web_service_call("StepName=getItemById_101",
4. "SOAPMethod=Cart|ICart|getItemById",
5. "ResponseParam=response",
6. "Service=Cart",
7. "ExpectedResponse=SoapResult",
8. "Snapshot=t1248415874.inf",
9. BEGIN_ARGUMENTS,
10. "id=1",
11. END_ARGUMENTS,
12. BEGIN_RESULT,
13. END_RESULT,
14. LAST);
15.
16. lr_message(lr_eval_string("ResponseXMLis\n{response}"));
17.
18. soap_request("StepName=SOAPRequest",
19. "URL=
20. "SOAPEnvelope="
21. "
xmlversion=\"1.0\"encoding=\"UTF-8\"?
>"
22. " 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\">" 23. " Body>" 24. " 25. " 26. "" 27. " Body>" 28. "
Envelope>",
29. "SOAPAction=getItemByTitle",
30. "ResponseParam=response",
31. "Snapshot=t1248416271.inf",
32. LAST);
33.
34. lr_message(lr_eval_string("ResponseXMLis\n{response}"));
35.
36. return0;
37. }
最后运行脚本。
输出的结果如下所示:
【原文:
WebServicestestinginLoadRunner
SometimeagoIdescribedhowtotestwebservicesinLoadRunnerwithHTTP/HTMLscript.RightnowIwouldliketodescribethecorrectway–testingwithWebServicesscript.
Firstofallweneedawebservices.Andthereisoneavailableexactlyfortraining.HereistheWSDLIhopethatfolksfromParasoftdon’tmindwearenotusingSOATest
Inanycase,wehaveanWSDLfile.Nowletscreatenewscript.
ClickFile/Newandselect“WebServices”fromlistofavailablescriptstypes.
Now,whenwehavenewscriptweshouldseenewtoolbarunderthestandardone.ItallowstoaddWebServicesdescriptiontothescript(fromWSDLfile),addXMLrequestusingformandaddXMLrequestfromfile.Soletsclickon“ManageServices”buttonandthen“Import”.EnterWSDLurlandclick“Import”.
AfterWSDLfileisimported,justclick“Apply”and“OK”.FromthispointLoadRunnerhasdescriptionofourwebservicessowecanuseitsendsomerequests.Wewillactuallycreatetworequests.Oneusing“AddServiceCall”andsecondusing“ImportSOAP”buttonsfromtoolbar.
Clickon“AddServiceCall”.In“Operation”dropdownlistselectvalue“getItemById”.Onleftsideselect“id”underInputArgumentstreenode.Thenonrightsidetype“1″intoValueeditbox.
Nowourscriptshouldlooklikethis:
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;
}
NowletsaddWebServicerequestusingImportSOAP.LetsassumewehaveXMLrequestsavedinfileonthedisk.Hereisanexample:
xmlversion="1.0"encoding="UTF-8"?
>
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"> Body> Body>
Envelope>
Click“ImportSOAP”buttonandselectyourfile.Changetypefrom“WebServiceCall(Recommended)”to“SOAPRequest”.SelectURLfromthelist,andtypeintoSOAPActionthisvalue“getItemByTitle”.ClickOK.
Nowwe’veaddedsecondcallthataskforbookdetailsfortitle“Linux”.Ourscriptshouldlooklikethis:
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=SOAPRequest",
"URL=
"SOAPEnvelope="
"
xmlversion=\"1.0\"encoding=\"UTF-8\"?
>"
" 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\">" " Body>" " " "" " Body>" "
Envelope>",
"SOAPAction=getItemByTitle",
"ResponseParam=response",
"Snapshot=t1248416271.inf",
LAST);
return0;
}
Asyoucansee,eachrequestcontain“ResponseParam=response”.LoadRunnerwillautomaticallysaveresponseXMLintoparameterwithname“response”.Wecaneasilydisplaythisparameterbyaddind
lr_message(lr_eval_string("ResponseXMLis\n{response}"));
aftereachcall.Soattheendoutscriptshouldlooklikethis:
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("ResponseXMLis\n{response}"));
soap_request("StepName=SOAPRequest",
"URL=
"SOAPEnvelope="
"
x
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 用LoadRunner测试Web Services 协议 LoadRunner 测试 Web