前不久,如何用Loadrunner做webservices测试http/html脚本。现在我想要描述的正确方法-用Web Services测试脚本。
首先需要一个web services 网址,并且是可以使用的网址。这是一个WSDL的地址:http://soatest.parasoft.com/store-01.wsdl 我希望Parasoft 不要介意我使用的SOAT 测试。另外,我们要有一份WSDL文件。现在让我们创造的脚本。
点击 新建/从脚本协议中选择 ‘Web Services’脚本类型
现在,当我们新建一个脚本,都会产生一个新的标准的工具栏。他允许添加webservice中描述的脚本文件,可以显示xml请求数据和返回的数据。所以点击 ‘管理服务’,接着‘导入’,在URL中输入 http://soatest.parasoft.com/store-01.wsdl,点击 ‘导入’
接着 WSDL 文件已经导入,直接点击 ‘应用’和‘确定’。在这里Loadrunner把web service引用的参数全部列举。我们准备创建2个实际请求数。在工具栏中,实现2个操作,一个是“增加呼叫服务”,另外一个是’导出 SOAP’
点击‘Add Service Call’。在‘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. return 0;
16. }
现在我们增加一个web service 请求导入SOAP 中。我们假定我们已经在XML文件的保存在磁盘中。下面是一个例子:<?xml version="1.0" encoding="UTF-8"?>
1. <SOAP-ENV:Envelope xmlns: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. <SOAP-ENV:Body>
3. <getItemByTitle xmlns="http://www.parasoft.com/wsdl/store-01/">
4. <titleKeyword>Linux</titleKeyword>
5. </getItemByTitle>
6. </SOAP-ENV:Body>
7. </SOAP-ENV:Envelope>
点击 “导入 SOAP” 按钮 和选择你的文件。在’ Web Service Call (Recommended)’中更改 “SOAP Request” 的类型。在清单中选择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.