性能测试学习05_lr(根据接口文档写脚本+参数化)
1、根據(jù)接口文檔寫腳本,函數(shù)(web_custom_request),完成get,post請求(注冊,登錄)
代碼:
Action() {lr_save_string("請?zhí)顚懩愕腎P", "IP");//注冊/*web_custom_request("register","URL=http://{IP}/mobile/api/user/register","Method=POST","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json;charset=utf-8","Body={\"mobile\":\"{mobile_mysql}\",\"password\":\"123456\",\"code\":\"3367\",\"platform\":\"windows\"}",LAST);*///設置token關聯(lián) web_reg_save_param_ex("ParamName=token","LB=token\":\"","RB=\",",//"DFEs=test",//"NotFound=warning","Ordinal=1",//"SaveOffset=2",//"SaveLen=3", SEARCH_FILTERS,"Scope=ALL",//"RelFrameID=1",//"RequestUrl=testURL",//"ContentType=text/html", LAST );//lr_output_message("token:%s",lr_eval_string("{token}"));//登錄web_custom_request("login","URL=http://{IP}/mobile/api/user/login ","Method=POST","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json ","Body={\"mobile\":\"{mobile_mysql}\",\"password\":\"123456\"}",LAST);lr_error_message("手機號:%s",lr_eval_string("{mobile_mysql}"));//獲取商品列表web_custom_request("getorders","URL=http://{IP}/mobile/api/goods/gettypes ","Method=GET","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json ","Body={\"type\":1}",LAST);return 0; }2、用登錄接口進行參數(shù)化的九種方式取值,自己總結
舉例說明:通過num:1、2、3、4、5,迭代6次對九種方式的運行結果及代碼如下:
Action() {lr_error_message("本次數(shù)字是:%s",lr_eval_string("{num}"));return 0; }3、數(shù)據(jù)庫參數(shù)化(詳細步驟)
第一步安裝
? 第二步
第三步
第四步點擊【create】→【機器數(shù)據(jù)源】→【新建】→數(shù)據(jù)源類型選擇【用戶數(shù)據(jù)源】
第五步,點擊下一步,點擊完成
第六步,填寫數(shù)據(jù)庫連接信息,點擊【OK】,一路確定
第七步,填寫數(shù)據(jù)庫查詢語句,舉例:SELECT mobile FROM cb_account WHERE `password` = 'e10adc3949ba59abbe56e057f20f883e'
第八步,導入完成
4、設置迭代次數(shù)
?
以上接口信息都在給的虛擬機里面,安裝配置文件里面的命令啟動Tomcat,連上數(shù)據(jù)庫
預習(C語言基本知識),完成易捷的(登錄,下訂單,支付訂單)的腳本(已完成
Action(){lr_save_string("請?zhí)顚懩愕腎P", "IP");//注冊/*web_custom_request("register","URL=http://{IP}/mobile/api/user/register","Method=POST","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json;charset=utf-8","Body={\"mobile\":\"{mobile_mysql}\",\"password\":\"123456\",\"code\":\"3367\",\"platform\":\"windows\"}",LAST);*///設置token關聯(lián) web_reg_save_param_ex("ParamName=token","LB=token\":\"","RB=\",",//"DFEs=test",//"NotFound=warning","Ordinal=1",//"SaveOffset=2",//"SaveLen=3", SEARCH_FILTERS,"Scope=ALL",//"RelFrameID=1",//"RequestUrl=testURL",//"ContentType=text/html", LAST );//登錄web_custom_request("login","URL=http://{IP}/mobile/api/user/login ","Method=POST","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json ","Body={\"mobile\":\"{mobile_mysql}\",\"password\":\"123456\"}",LAST);//重置支付密碼web_custom_request("resetpaywd","URL=http://{IP}/mobile/api/user/resetpaypwd","Method=POST","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json ","Body={\"token\":\"{token}\",\"password\":\"123456\"}",LAST);//lr_output_message("token:%s",lr_eval_string("{token}"));//獲取商品列表web_custom_request("gettypes","URL=http://{IP}/mobile/api/goods/gettypes","Method=GET","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json ","Body={\"type\":1}",LAST);//設置padId關聯(lián) web_reg_save_param_ex("ParamName=payId","LB=\"payId\":\"","RB=\",\"",//"DFEs=test",//"NotFound=warning","Ordinal=1",//"SaveOffset=2",//"SaveLen=3", SEARCH_FILTERS,"Scope=ALL",//"RelFrameID=1",//"RequestUrl=testURL",//"ContentType=text/html", LAST ); //lr_output_message("payId:%s",lr_eval_string("{payId}"));//下訂單web_custom_request("addorder","URL=http://{IP}/mobile/api/order/addorder","Method=POST","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json ","Body={\"token\":\"{token}\",\"getAddrId\":1,\"getCarId\":23,\"payType\":2,\"remark\":\"123\",\"price\":12,\"orders\":[{\"getTime\":1450921104000,\"goodss\":[{\"goodsId\":93,\"count\":1},{\"goodsId\":96,\"count\":1}]}],\"invoiceTitle\":\"fapiao\"}", LAST); //支付訂單web_custom_request("pay","URL=http://{IP}/mobile/api/pay/pay","Method=POST","TargetFrame=","Resource=1","Referer=","Mode=HTTP","EncType=application/json ","Body={\"token\":\"{token}\",\"payId\":\"{payId}\",\"payPwd\":\"123456\",\"platform\":3}",LAST);return 0;}?
轉載于:https://www.cnblogs.com/user-moxiaohao/p/10687730.html
總結
以上是生活随笔為你收集整理的性能测试学习05_lr(根据接口文档写脚本+参数化)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux的一些基本命令
- 下一篇: [BZOJ2655] calc