溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

loadrunner 測試webservice之二:通過soap_reuest

發布時間:2020-06-14 23:11:05 來源:網絡 閱讀:3107 作者:lyctest 欄目:軟件技術

    之前文章寫了一半,保存草稿后,最后發現全沒有了,只好重新來寫,這次也就不那么啰嗦了,主要把測試的步驟分享下。

    LoadRunner測試webservice共有3種方式:1、通過web_service_call函數,也就是導入wsdl文件或者URL的方式;2、通過soap_request函數,通過導入xml文件來實現;3、通過http協議來手寫腳本來實現。

    第一種可以訪問:http://gungun.blog.51cto.com/9585287/1591100

    今天的重點是第二種,通過Import SOAP來導入xml文件,從而實現對webservice接口的調用。

下面以大家都熟知的天氣預報為例:

    天氣預報的接口URL:http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx

調用getWeatherbyCityName方法。

打開http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx?op=getWeatherbyCityName 頁面,如下圖所示:

 

loadrunner 測試webservice之二:通過soap_reuest 

 

將下面紅框的部分保存到xml文件中,導入剛才的XML文件,如下圖所示:

loadrunner 測試webservice之二:通過soap_reuest

 

導入后自動生成以下代碼:

soap_request("StepName=SOAP Request",          
  "URL=http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx",          
  "SOAPEnvelope="
  "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
   "<soap12:Body>"
    "<getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">"
     "<theCityName>string</theCityName>"                         //這里填寫城市的名字
    "</getWeatherbyCityName>"
   "</soap12:Body>"
  "</soap12:Envelope>",          
  "SOAPAction=getWeatherbyCityName",          
  "ResponseParam=response",          
  "Snapshot=t1418827945.inf",            
  LAST);

 

然后在剛才生成的代碼前,增加header信息。需要增加的內容見第一個圖中,其中,“Content-Length”不需要加。

在該例子中需要增加的代碼如下:

web_add_header("POST",
       "/WebServices/WeatherWebService.asmx HTTP/1.1");
 web_add_header("Host",
       "webservice.webxml.com.cn");
 web_add_header("Content-Type",
       "application/soap+xml; charset=utf-8");                               //這里注意和截圖里有些不同
 web_add_header("SOAPAction",
       "\"http://WebXml.com.cn/getWeatherbyCityName\"");

 

這樣簡單的通過soap_request函數測試Webservice的方式就完成了。

 

取到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 string

lr_xml_find()  //Verifies that XML values are returned by a query

lr_xml_transform()  //Applies Extensible Stylesheet Language (XSL) Transformation to XML data

 

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女