性能測試學習05_lr(根據接口文檔寫腳本+參數化)

一、根據接口文檔寫腳本,函數(web_custom_request),完成get,post請求(註冊,登陸)html

代碼:mysql

Action()
{
    lr_save_string("請填寫你的IP", "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關聯
    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;
}

二、用登陸接口進行參數化的九種方式取值,本身總結   web

  舉例說明:經過num:一、二、三、四、5,迭代6次對九種方式的運行結果及代碼以下:sql

Action()
{
    
    lr_error_message("本次數字是:%s",lr_eval_string("{num}"));
    return 0;
}

三、數據庫參數化(詳細步驟)數據庫

  第一步安裝json

  

   第二步windows

  

  第三步api

  

  第四步點擊【create】→【機器數據源】→【新建】→數據源類型選擇【用戶數據源】app

  

  第五步,點擊下一步,點擊完成函數

  第六步,填寫數據庫鏈接信息,點擊【OK】,一路肯定

  第七步,填寫數據庫查詢語句,舉例:SELECT mobile FROM cb_account WHERE `password` = 'e10adc3949ba59abbe56e057f20f883e'

  第八步,導入完成

  

4、設置迭代次數

 

以上接口信息都在給的虛擬機裏面,安裝配置文件裏面的命令啓動Tomcat,連上數據庫

預習(C語言基本知識),完成易捷的(登陸,下訂單,支付訂單)的腳本(已完成

Action()

{
    lr_save_string("請填寫你的IP", "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關聯
    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關聯
    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;
 }
相關文章
相關標籤/搜索