qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

          精通軟件性能測試與LoadRunner最佳實戰(zhàn) 連載十四

          3.13.3  Web Services腳本

            完成Web Services服務端和客戶端兩個小程序的編寫、編譯、執(zhí)行后,您需要確保服務端程序是開啟的,關(guān)閉已運行的客戶端小程序。

            接下來,您啟動LoadRunner 11.0,選擇“Web Services”協(xié)議,如圖13-122所示。

               

           圖13-121 “樣例演示-客戶端”對話框              圖13-122 “New Virtual User”對話框

            單擊【Create】按鈕,創(chuàng)建“Web Services”協(xié)議,在LoadRunner 腳本編輯環(huán)境單擊錄制紅色按鈕,在彈出的“Recording Wizard”對話框中單擊【Import】按鈕,在彈出的“Import Service”對話框中選擇“URL”選項,在文本框中輸入“http://localhost:5678/wsdl/IMyHello”,單擊【Import】按鈕,如圖13-123所示。

            圖13-123 “Recording Wizard-Add Services頁”對話框

            稍等片刻,將出現(xiàn)圖13-124所示界面信息,單擊【下一步(N)>】按鈕。

            圖13-124 “Recording Wizard”對話框

            在圖13-125所示對話框中輸入客戶端路徑相關(guān)信息“C:\mytest\client\Client.exe”,工作目錄為“C:\mytest\client”,(如果您的應用是基于B/S的,則選擇“Record default web browser”選項并輸入相應URL)單擊【完成】按鈕。

           此時將會在輸入框下方出現(xiàn)“歡迎于涌同學!”字符串,如圖13-126所示。

                           

           圖13-125 “Recording Wizard-Specify Application頁”對話框     圖13-126 “樣例演示-客戶端”對話框

            此時將會產(chǎn)生如下代碼:

          Action()

          {

          web_add_header("Content-Type", "text/xml");

          web_add_header("SOAPAction", "\"urn:MyHelloIntf-IMyHello#Welcome\"");

          web_add_header("User-Agent", "Borland SOAP 1.2");

          soap_request("StepName=Welcome", 

          "URL=http://localhost:5678/soap/IMyHello", 

          "SOAPEnvelope=<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\"?"

          "><SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/"

          "encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "

          "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENV=\"http:/"

          "/schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body SOAP-ENV"

          ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><NS1"

          ":Welcome xmlns:NS1=\"urn:MyHelloIntf-IMyHello\"><name xsi:type=\"xsd"

          ":string\">于涌</name></NS1:Welcome></SOAP-ENV:Body></SOAP-ENV:Envelope>", 

          "Snapshot=t1.inf", 

          "ResponseParam=response", 

          LAST);

          return 0;

          }

            我們最關(guān)心的內(nèi)容應該是Web Services服務接口返回的內(nèi)容,所以需要對腳本進行完善,腳本信息如下,黑色字體為新添加內(nèi)容。

          Action()

          {

          web_add_header("Content-Type", "text/xml");

          web_add_header("SOAPAction", "\"urn:MyHelloIntf-IMyHello#Welcome\"");

          web_add_header("User-Agent", "Borland SOAP 1.2");

          soap_request("StepName=Welcome", 

          "URL=http://localhost:5678/soap/IMyHello", 

          "SOAPEnvelope=<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\"?"

          "><SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/"

          "encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "

          "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENV=\"http:/"

          "/schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body SOAP-ENV"

          ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><NS1"

          ":Welcome xmlns:NS1=\"urn:MyHelloIntf-IMyHello\"><name xsi:type=\"xsd"

          ":string\">于涌</name></NS1:Welcome></SOAP-ENV:Body></SOAP-ENV:Envelope>", 

          "Snapshot=t1.inf", 

          "ResponseParam=response", 

          LAST);

               lr_save_string(lr_eval_string("{response}"), "XML_Input_Param"); 

               lr_xml_get_values("XML={XML_Input_Param}",

                    "ValueParam=OutputParam",

                    "Query=/*/*/*/return",

                    LAST );

               lr_output_message(lr_eval_string("返回結(jié)果 = {OutputParam}"));

          return 0;

          }

            腳本的執(zhí)行信息如下:

          Virtual User Script started at : 2012-11-11 14:56:30

          Starting action vuser_init.

          Ending action vuser_init.

          Running Vuser...

          Starting iteration 1.

          Starting action Action.

          Action.c(4): Warning -26593: The header being added may cause unpredictable results when

           applied to all ensuing URLs. It is added anyway   [MsgId: MWAR-26593]

          Action.c(4): web_add_header("Content-Type") highest severity level was "warning"   [MsgId: MMSG-26391]

          Action.c(6): web_add_header("SOAPAction") was successful   [MsgId: MMSG-26392]

          Action.c(8): web_add_header("User-Agent") was successful   [MsgId: MMSG-26392]

          Action.c(10): SOAP request "Welcome" started

          Action.c(10): SOAP request "Welcome" was successful

          Action.c(26): "lr_xml_get_values" succeeded, 1 match processed

          Action.c(31): 返回結(jié)果 = 歡迎于涌同學!

          Ending action Action.

          Ending iteration 1.

          Ending Vuser...

          Starting action vuser_end.

          Ending action vuser_end.

          Vuser Terminated.

            也許有的讀者會說:“我想先看看服務端返回的信息,這可不可以呢?”。“當然沒問題”,您只需要在腳本中加入“lr_output_message("%s",lr_eval_string("{response}")); ”(lr_xml_get_values()函數(shù)在前面已經(jīng)介紹過,其在進行該協(xié)議類型腳本關(guān)聯(lián)時非常重要,請讀者朋友務必掌握),執(zhí)行腳本時就會打印出響應的相關(guān)數(shù)據(jù)信息,如圖13-127所示。

            圖13-127  WebServices相關(guān)腳本及執(zhí)行結(jié)果

            為了讓大家對返回的內(nèi)容看得更加清楚,這里我將其拷貝出來,放置到my.xml文件中,其內(nèi)容如圖13-128所示。

            圖13-128  服務返回的XML相關(guān)信息

            從圖13-128您會看到有一串亂碼,憑直覺這應該是“歡迎于涌同學!”,那么直覺對不對呢?您可以在腳本中加入以下兩行代碼,如圖13-129所示。

            圖13-129  轉(zhuǎn)碼及輸出函數(shù)

            其輸出結(jié)果果真為“歡迎于涌同學!”。圖13-129 中使用“lr_convert_string_encoding()”的函數(shù)就是將UTF8編碼轉(zhuǎn)碼為系統(tǒng)語言編碼的函數(shù),經(jīng)過轉(zhuǎn)碼后信息顯示正確了。也許有的讀者會問:“系統(tǒng)返回的xml響應信息有些顯得十分混亂,有沒有什么方法直接能看出其層次關(guān)系呢?”您可以借助樹視圖,單擊“Tree”按鈕,將出現(xiàn)圖13-130所示界面信息,是不是一目了然了呢!這也方便了您應用lr_xml_get_values()函數(shù)時填寫“Query”部分內(nèi)容。

          圖13-130  WebServices響應結(jié)果樹視圖

           【重要提示】

            (1)從上面Web Services程序編寫和腳本應用中,相信大家對該協(xié)議的應用已經(jīng)有了非常清晰的認識,我們給大家演示的是基于C/S的小程序,在實際工作中您測試的應用可能是基于B/S的,它們在實際應用上并沒有大的區(qū)別,所以請讀者朋友們舉一反三。

            (2)也許您也會像我一樣,在機器上安裝有殺毒軟件,如果您應用本書此客戶端和服務器端小程序時,有可能您的殺毒軟件會對其產(chǎn)生干擾,如:將小程序自動刪除、運行小程序沒反應等情況,此時應暫時關(guān)閉殺毒軟件,確保小應用可以正常運行。

          (未完待續(xù))

          版權(quán)聲明:51Testing軟件測試網(wǎng)及相關(guān)內(nèi)容提供者擁有51testing.com內(nèi)容的全部版權(quán),未經(jīng)明確的書面許可,任何人或單位不得對本網(wǎng)站內(nèi)容復制、轉(zhuǎn)載或進行鏡像。51testing軟件測試網(wǎng)歡迎與業(yè)內(nèi)同行進行有益的合作和交流,如果有任何有關(guān)內(nèi)容方面的合作事宜,請聯(lián)系我們。

          相關(guān)鏈接:

          精通軟件性能測試與LoadRunner最佳實戰(zhàn) 連載十三

          posted on 2013-07-25 10:50 順其自然EVO 閱讀(777) 評論(0)  編輯  收藏 所屬分類: loadrunner

          <2013年7月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 城口县| 永丰县| 安远县| 红原县| 武穴市| 肥西县| 阳新县| 乌拉特前旗| 石首市| 阜平县| 黎平县| 九江县| 托里县| 龙门县| 泗洪县| 独山县| 都兰县| 岳普湖县| 河北省| 嘉祥县| 玛多县| 东兰县| 岑溪市| 伊川县| 定远县| 大洼县| 阳原县| 岳池县| 惠安县| 方正县| 桑日县| 电白县| 星座| 威宁| 铜陵市| 腾冲县| 大方县| 西城区| 乌拉特前旗| 天等县| 古浪县|