打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用LoadRunner测试Web Services
前不久,如何用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.               BEGIN_ARGUMENTS,
10.                "id=1",
11.                END_ARGUMENTS,
12.                BEGIN_RESULT,
13.                END_RESULT,
14.                LAST);
15.           soap_request("StepName=SOAP Request",
16.               "URL=http://ws1.parasoft.com/glue/store-01",
17.               "SOAPEnvelope="
18.               "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
19.               "<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\">"
20.               "<SOAP-ENV:Body>"
21.               "<getItemByTitle xmlns=\"http://www.parasoft.com/wsdl/store-01/\">"
22.               "<titleKeyword>Linux</titleKeyword>"
23.               "</getItemByTitle>"
24.               "</SOAP-ENV:Body>"
25.               "</SOAP-ENV:Envelope>",
26.               "SOAPAction=getItemByTitle",
27.               "ResponseParam=response",
28.               "Snapshot=t1248416271.inf",
29.               LAST);
30.           return 0;
31.        }

  正如你所见的,每个请求都包含在“ResponseParam=response”,LoadRunner将会自动保存返回到XMl的参数化到表’repose’。我们可以得到显示该参数化返回的结果。最后,脚本应该就如下所示:
1.        lr_message(lr_eval_string("Response XML is \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("Response XML is \n{response}"));
17.         
18.           soap_request("StepName=SOAP Request",
19.               "URL=http://ws1.parasoft.com/glue/store-01",
20.               "SOAPEnvelope="
21.               "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
22.               "<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\">"
23.               "<SOAP-ENV:Body>"
24.               "<getItemByTitle xmlns=\"http://www.parasoft.com/wsdl/store-01/\">"
25.               "<titleKeyword>Linux</titleKeyword>"
26.               "</getItemByTitle>"
27.               "</SOAP-ENV:Body>"
28.               "</SOAP-ENV:Envelope>",
29.               "SOAPAction=getItemByTitle",
30.               "ResponseParam=response",
31.               "Snapshot=t1248416271.inf",
32.               LAST);
33.         
34.           lr_message(lr_eval_string("Response XML is \n{response}"));
35.         
36.           return 0;
37.        }

  最后运行脚本。输出的结果如下所示:


原文:
Web Services testing in LoadRunner
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);
   return 0;
}
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:

<?xml version="1.0" encoding="UTF-8"?>
<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">
<SOAP-ENV:Body>
  <getItemByTitle xmlns="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="
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
       "<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\">"
       "<SOAP-ENV:Body>"
       "<getItemByTitle xmlns=\"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="
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
       "<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\">"
       "<SOAP-ENV:Body>"
       "<getItemByTitle xmlns=\"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:


 
 
备注:在google中键入“Action.c(5): Error: Internal error, please call customer support. Details: class java.lang.Object :”,选择“LR测试webservice 脚本回放报错- HP LoadRunner - 7点测试网”,进入“http://www.7dtest.com/bbs/viewthread.php?action=printable&tid=3494
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
XML认证教程,第 10 部分: Web 服务
使用Soap消息调用Web Services
SOAP for Python [知识库]
了解 Web 服务规范,第 1 部分: SOAP
SOAP净化有线协议(一):SOAP基础知识
中华网校-WSDL文件详解(上)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服