LoadRunner 如何進行接口的壓力測試

主要壓測的時候須要開發提供相關接口文檔,或者本身錄製。
左側的Name都是開發提供的接口參數名稱,Value是相應的參數值。Action爲開發給的測試地址。
PS:注意在測試的時候設置Controller的Run time seting  Pacing的值爲With a fixed delay of X seconds。還要注意在壓測的時候觀察服務器的CPU利用率已經內存使用狀況。

        web_submit_data("insert",
                "Action= http://116.211.23.121/app/Jigsaw/GetResult.ashx",
                "Method=GET",
                "Referer= http://116.211.23.121/home.aspx",
                                 "Mode=HTML",
                ITEMDATA,
                "Name=uid","Value={myUid}",ENDITEM,
                "Name=id","Value=4",ENDITEM,
                "Name=time","Value=00:00:{ss}",ENDITEM,
                "Name=piecewn","Value={myPiecewn}",ENDITEM,
                "Name=piecehn","Value={myPiecehn}",ENDITEM,
                LAST);


char str[1000];
strcpy(str,"SNSID=7999&UserID=1&CommentsTypeID=1&CommentsID=1&AuthorID=1&CommentsContent=1");
web_custom_request("Publish",
     "Url= http://10.240.248.103:7006/Comment/{IID}",
     "Method=POST",
     "Referer= http://10.240.248.103:7006/Comment/{IID}",
     "Mode=HTTP",
     str,
    LAST);
這也是一種寫法,能夠跟web_submit_data互換。這種寫法更利於拼接參數。web

 

這個只是一個簡單的LR API函數,還須要對腳本使用web_reg_find()作一個最終的結果檢查:
PS:下面的例子是我之前寫的一個腳本的例子,對最終的返回結果要最好有一個結果檢查,這樣子比較合理些。
Action()
{
        web_reg_find("Search=Body", //定義查找範圍
    "SaveCount=result", //定義查找計數變量名稱
    "Text=領取成功", //定義查找內容
     LAST);

//發送請求
        web_submit_data("GetActivativeCode",
                "Action= http://192.168.101.181:8931/project/libao/bf.asp",
                "Method=POST",
                "Referer= http://192.168.101.181:8931/project/libao/bf.asp",
        "Mode=HTML",
                 ITEMDATA,
        "Name=Jcode","Value=4",ENDITEM,
        "Name=Account","Value=zhzh1986",ENDITEM,
                    LAST);

        if (atoi(lr_eval_string("{result}")) > 0) //判斷若是Welcome字符串出現次數大於0
        lr_output_message("Log on successful."); //在日誌中輸出Log on successful
    else
                //若是出現次數小於等於
       lr_error_message("Log on failed"); //在日誌中輸出Log on failed

        return 0;
}

下面給樓主2個例子,參考如下,而後主要壓測的時候須要開發提供相關接口文檔,或者本身錄製。
左側的Name都是開發提供的接口參數名稱,Value是相應的參數值。Action爲開發給的測試地址。
PS:注意在測試的時候設置Controller的Run time seting  Pacing的值爲With a fixed delay of X seconds。還要注意在壓測的時候觀察服務器的CPU利用率已經內存使用狀況。

        web_submit_data("insert",
                "Action= http://116.211.23.121/app/Jigsaw/GetResult.ashx",
                "Method=GET",
                "Referer= http://116.211.23.121/home.aspx",
                                 "Mode=HTML",
                ITEMDATA,
                "Name=uid","Value={myUid}",ENDITEM,
                "Name=id","Value=4",ENDITEM,
                "Name=time","Value=00:00:{ss}",ENDITEM,
                "Name=piecewn","Value={myPiecewn}",ENDITEM,
                "Name=piecehn","Value={myPiecehn}",ENDITEM,
                LAST);


char str[1000];
strcpy(str,"SNSID=7999&UserID=1&CommentsTypeID=1&CommentsID=1&AuthorID=1&CommentsContent=1");
web_custom_request("Publish",
     "Url= http://10.240.248.103:7006/Comment/{IID}",
     "Method=POST",
     "Referer= http://10.240.248.103:7006/Comment/{IID}",
     "Mode=HTTP",
     str,
    LAST);
這也是一種寫法,能夠跟web_submit_data互換。這種寫法更利於拼接參數。服務器

相關文章
相關標籤/搜索