LR手工制作接口類腳本


 

首先通過抓包獲得某個接口的碼流消息,請求報文碼分消息頭和消息體,所以在制作腳本的時候也需要添加消息頭和消息體。

POST /jboss-bet/services/&** HTTP/1.1
SOAPAction: ""
Content-Type:text/xml; charset=utf-8
Host: 10.0.0.0:8080
Connection: close
Content-Length:1004

<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc>
<soapenv:Body>
<ns1:請求 xmlns:ns1="http://ww.***.com">
<event>
<portalAccount xsi:type="xsd:string">admin</portalAccount>
<portalPwd xsi:type="xsd:string">123456</portalPwd>
</event>
</ns1:**>
</soapenv:Body>
</soapenv:Envelope>

消息頭可以用web_add_header或者是web_add_auto_header函數來添加,2個函數只是位置不同,web_add_auto_header可以放在 init或者action里面,而web_add_header只能放在action里

web_add_header("Content-Type","text/xml;charset=utf-8");
web_add_header("Host","10.0.0.0:8080");

而消息體可以用web_custom_request函數來添加

web_custom_request("**",--自定義請求名稱,便於理解
"URL=http://10.0.0.0/8080/jboss-bet/services/&**",
"Method=POST",
"Resource=0",
"Referer=",
"Mode=HTTP",
"Body"
--消息體
"<?xml version= \"1.0\" encoding=\"utf-8\" ?>"
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc>"
"<soapenv:Body>"
"<ns1:** xmlns:ns1=\"http://ww.***.com\">"
"<event>"
"<portalAccount xsi:type=\"xsd:string\">admin</portalAccount>"
"<portalPwd xsi:type=\"xsd:string\">123456</portalPwd>"
"</event>"
"</ns1:**>"
"</soapenv:Body>"
"</soapenv:Envelope>"
)
這里要注意的是 消息體,在消息碼流的引號“”,在loadrunner中並不識別,必須在引號前面加上\符號,也就是這種形式:\“\”。
至此,腳本就算制作完了。

再來講一下關聯

web_reg_save_param("Miyi","LB=<returnCode>","RB=</returnCode>",LAST);

這就是個簡單關聯,它關聯的是什么呢?

看報文都知道,請求后面跟相應,而LR模擬的是請求,但往往很多時候,一次請求后下一次請求需要根據第一次請求給出相應的動態碼進行第二次請求,所以這時候我們就用到了關聯。看下面這個例子:

lr_output_message(lr_eval_string("{Miyi}"));
       if (strcmp(lr_eval_string("{Miyi}"), "00000") == 0){
            lr_end_transaction("login",LR_PASS);
               }
        else{         
           lr_end_transaction("login", LR_FAIL);
        }

還可以用關聯寫一個檢查點,你也可以試試吧。

再加一個檢測點:

web_reg_find("Text=wangyuxing",
"SaveCount=yw",
LAST);

怎么判斷呢?

if(atoi(lr_eval_string("{yw}"))>0){
          lr_output_message("wangyong :  ok  !");
                }
        else{
          lr_output_message("wangyong :  no   !");
                }

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM