专注于软件性能测试与自动化测试的学习与应用

Web Services testing in LoadRunner

上一篇 / 下一篇  2011-06-11 10:41:06 / 个人分类: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.

1

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”.

2

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.

3

Now our script. should look like this:

  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. }

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:

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <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">
  3.  <SOAP-ENV:Body>
  4.  <getItemByTitlexmlns="http://www.parasoft.com/wsdl/store-01/">
  5.    <titleKeyword>Linux</titleKeyword>
  6.  </getItemByTitle>
  7.  </SOAP-ENV:Body>
  8. </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:

  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.        "<?xmlversion=\"1.0\"encoding=\"UTF-8\"?>"
  19.        "<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\">"
  20.        "<SOAP-ENV:Body>"
  21.        "<getItemByTitlexmlns=\"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. }

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

  1. lr_message(lr_eval_string("Response XML is\n{response}"));

after each call. So at the end out script. should look like this:

  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.        "<?xmlversion=\"1.0\"encoding=\"UTF-8\"?>"
  22.        "<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\">"
  23.        "<SOAP-ENV:Body>"
  24.        "<getItemByTitlexmlns=\"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. }

At the end lets run our script. Output should be something like this:

4


TAG: LoadRunner loadrunner Loadrunner webservice WebService

 

评分:0

我来说两句

cow

cow

个人主要专注于性能测试与自动化测试方向的学习与应用

日历

« 2024-04-19  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 12830
  • 日志数: 13
  • 建立时间: 2011-03-08
  • 更新时间: 2011-06-12

RSS订阅

Open Toolbar