Loadrunner 9.5_webservice(SOAP)效能測試

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   os   使用   sp   

WebService定義:
Webservice是一種新的使用基於XML標準和協議來交換資訊的WEB應用程式。是基於SOAP(簡易物件存取通訊協定 (SOAP))訊息的應該協議,只是為WEB頁面或可執行程式提供編程介面。
個人理解:就是webservice服務與用戶端的資料交流是通過XML來實現,XML檔案就是介面,用戶端發送XML檔案的請求,XML檔案中有要調要背景方法和傳送的資料等資訊。伺服器返回結果到用戶端也是XML檔案,
 
註:基於Webservice構建的應該系統稱之為SOA(面向服務架構),系統效能取絕於服務元件的單獨效能以及介面效能。
 
名司解釋
在構建和使用Web Service時,主要用到以下幾個關鍵的技術和規則:
  1.XML:描述資料的標準方法.
  2.SOAP:表示資訊交換的協議.
  3.WSDL:Web服務描述語言.
4.UDDI(Universal Description, Discovery and Integration):通用描述、發現與整合,它是一種獨立於平台的,基於XML語言的用於在互連網上描述商務的協議。
 
用Loadrunner測試webservice測試一般步聚是:
 
(1)     選擇Loadrunner的webservice協議
(2)     匯入WSDL。 個人認為是讓LR同Webservice建立串連,如果匯入成功後,在Operations欄中可以看到webservice介面提供的方法
特別注意:如果webservier是asp.net開發以“*.asmx”結尾的路徑。要加上“?wsdl”才能成功。如:http://192.168.0.30/securityws/SecurityWebService/SecurityWS.asmx?wsdl。
總之,應該是以wsdl結尾才正常吧
(3)     Webservice匯入LR成功後,我們可以建立兩種請求中的任意一個,
第一種是:“add service call”,
第二種是.“ Import SOAP”,
 
(4)     建立相關請求,產生代碼,並參數化。
(5)     列印響應資訊功能,調試代碼,直到成功。
如:lr_message(lr_eval_string("Response XML is \n{response}"));
如上參見:http://blog.testsautomation.com/2009/07/web-services-testing-in-loadrunner/
 
LR WEBSERVICE效能測試
 
LR在WebService虛擬使用者協議中支援兩種方式測試WebService,一種是通過“Add Service Call”的方式,一種是Import SOAP的方式。
Import SOAP的方式需要匯入定義好的XML請求檔案。
取到WebService返回的XML資料後,可以使用XPath的方式驗證資料,LR提供了幾個處理XML的函數:
lr_xml_get_values()  //Retrieves values of XML elements found by a query
lr_xml_set_values()  //Sets the values of XML elements found by a query
lr_xml_extract()  //Extracts XML string fragments from an XML string
lr_xml_delete()  //Deletes fragments from an XML string
lr_xml_replace()  //Replaces fragments of an XML string
lr_xml_insert()  //Inserts a new XML fragment into an XML strin
lr_xml_find()  //Verifies that XML values are returned by a query
lr_xml_transform()  //Applies Extensible Stylesheet Language (XSL) Transformation to XML data
參見:http://blog.testsautomation.com/2009/05/validating-web-service-response-with-xpath/
 
實際上,使用LR還有一種測試WebService的方式,就是採用HTTP協議,因為WebService是構建在HTTP協議之上的,因此可以WEB虛擬使用者協議中的web_custom_request來構造WebService的請求。
 
Action()
{
   web_reg_save_param("Response","LB=", "RB=", LAST);
   web_add_header("SOAPAction", "SampleMethod");
   lr_start_transaction("REQ");
   web_custom_request("Sample_Request","Method=POST",
         "Mode=HTML",
         "RecContentType=text/xml",
         "EncType=text/xml; charset=utf-8",
         "URL=http://example.com:1234/sample/",
         "Body=<Envelope xmlns=\"\n‘<http://example.com/sample\">\n"
               "   <Header/>\n"
               "   <Body>\n"
               "      <price><id>001</id></price>\n"
               "   </Body>\n"
               "</Envelope>",
   "LAST");
   lr_end_transaction("REQ", LR_AUTO);
   lr_output_message("Response is : %s\n", lr_eval_string("{Response}"));
   return 0;
}
 
參見:http://blog.testsautomation.com/2009/01/web-services-performance-using-loadrunner/
 
學習LR測試WebService時,如果沒有現成的WebService,又懶得寫或不會寫,可以用Parasoft網站的WSDL來實驗:
http://soatest.parasoft.com/store-01.wsdl
、
 
範例程式碼                    
1.  <books>
2.    <book>
3.        <id>123</id>
4.        <author>John Smith</author>
5.        <title>Working with Legacy code</title>
6.        <publisher>Microsoft</publisher>
7.    </book>
8.  </books>
Action()
{
     web_add_header("SOAPAction", "\"CallMe\"");
     lr_start_transaction("AUTHOR");
     soap_request("StepName=Sample Soap Request",
       "ExpectedResponse=ANY",
       "URL=http://foo.com/api",
       "SOAPEnvelope= "
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
       "<soap:Envelope "
       "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" >"
       "<soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
       "<GetBookDetails>"
       "<idValue>123</idValue>"
       "</GetBookDetails>"
       "</soap:Body>"
       "</soap:Envelope>",
       "Snapshot=t765765765.inf",
       "ResponseParam=Response_Xml",LAST);
 
 
     lr_xml_get_values("XML={Response_Xml}",
          "ValueParam=Author_Name",
          "Query=/books/book/author",
          LAST);
 
     lr_output_message(lr_eval_string("Author is = {Author_Name}"));
 
     if(strcmp(lr_eval_string("{Author_Name}"),"John Smith") == 0)
     {
        lr_end_transaction("AUTHOR", LR_PASS);
     }
     else
     {
        lr_end_transaction("AUTHOR", LR_FAIL);
     }
     return 0;
}

Loadrunner 9.5_webservice(SOAP)效能測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.