性能测试学习04_lr(fiddler+前程贷)

1、完成XX贷的(登录,投标)

2、所有的返回信息都用关联函数(web_reg_save_param_ex)进行关联

3、对返回信息用(strcmp)函数进行if判断

代码:

Action()
{

lr_save_string("请填写你的IP", "IP");
//关联登录成功
    web_reg_save_param_ex(
        "ParamName=success",
        "LB=<p class=\"success\">",
        "RB=</p>",
        //"DFEs=test",
        //"NotFound=warning",
        "Ordinal=1",
        //"SaveOffset=2",
        //"SaveLen=3",
        SEARCH_FILTERS,
        "Scope=ALL",
        //"RelFrameID=1",
        //"RequestUrl=testURL",
        //"ContentType=text/html",
        LAST );

//登录成功
    lr_start_transaction("登录成功");

    web_submit_data("web_submit_data",
     "Action=http://{IP}/Frontend/Index/login",
     "Method=POST",
     "TargetFrame=",
     "RecContentType=application/json, text/javascript, */*; q=0.01",
     "EncType=application/x-www-form-urlencoded; charset=UTF-8",
     "Referer=http://{IP}/Index/login.html",
     "Snapshot=t22.inf",
     "Mode=HTML",
     ITEMDATA,
     "Name=phone", "Value=13825161923", ENDITEM,
     "Name=password", "Value=lemon123", ENDITEM,
     "Name=vcode", "Value=", ENDITEM,
     "Name=remember_me", "Value=1", ENDITEM,
     "Name=notify_url", "Value=", ENDITEM,
     LAST );

//判断是否登录成功
    //lr_end_transaction("登录成功", LR_AUTO);
       //strcmp(str1,str2):比较两str的大小
       if(strcmp(lr_eval_string("{success}"),"登录成功")==0)
    {
       lr_end_transaction("登录成功",LR_PASS);
       lr_error_message("登录成功:%s",lr_eval_string("{success}"));
    }
   else
    {
       lr_end_transaction("登录成功",LR_FAIL);
    }
    

//获取投资ID
    web_reg_save_param_ex(
        "ParamName=id",
        "LB=href=\"/loan/loan_detail/Id/",
        "RB=.html",
        "Ordinal=ALL",
        //"SaveOffset=1",
        SEARCH_FILTERS,
        LAST);

    web_url("web_url",
      "URL=http://{IP}/Index/login.html",
      "TargetFrame=",
      "Resource=0",
      "Referer=",
      "Mode=HTML",
      LAST);

    //lr_error_message("id:%s",lr_eval_string("{id_1}"));

//关联token
    web_reg_save_param_ex(
        "ParamName=token",
        "LB=data-token=\"",
        "RB=\"",
        "Ordinal=1",
        //"SaveOffset=1",
        SEARCH_FILTERS,
        LAST);
     web_url("web_url",
       "URL=http://{IP}/loan/loan_detail/Id/{id_1}.html",
       "RecContentType=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
       "Mode=HTML",
       LAST);

    //lr_error_message("token的值是:%s",lr_eval_string("{token}"));


//关联state=1
    web_reg_save_param_ex(
        "ParamName=state",
        "LB={\"state\":",
        "RB=,\"msg\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );

//投资操作
    lr_start_transaction("投资成功");

    web_submit_data("invest",
     "Action=http://{IP}/Invest/invest",
     "Method=POST",
     "TargetFrame=",
     "RecContentType=application/json, text/javascript",
     "Referer=http://{IP}/loan/loan_detail/Id/{id_1}.html",
     "Mode=HTML",
     ITEMDATA,
     "Name=id", "Value={id_1}", ENDITEM,
     "Name=val", "Value=100", ENDITEM,
     "Name=token", "Value={token}", ENDITEM,
     "Name=rewardValue", "Value=0", ENDITEM,
     LAST );

//判断是否投资成功
    //lr_end_transaction("投资成功", LR_AUTO);
       //strcmp(str1,str2):比较两str的大小
       if(strcmp(lr_eval_string("{state}"),"1")==0)
    {
       lr_end_transaction("投资成功",LR_PASS);
       lr_error_message("本次投标id:%s,本次投资状态是:%s",lr_eval_string("{id_1}"),lr_eval_string("{state}"));

    }
   else
    {
       lr_end_transaction("投资成功",LR_FAIL);
    }

}

 

4、预习(lr_save_string,web_custom_request)函数和参数化

  1)lr_save_string函数主要用来做字符串参数化

  举例: char*name_all="性能测试三期-沫小豪"

      char*name="沫小豪"

        lr_save_string(name,"name")

      char*name_all="性能测试三期-{name}"

  2)web_custom_request可以直接复制抓包来的body 中的参数串,可以参考博文连接https://www.cnblogs.com/qmfsun/p/4481444.html

posted @ 2019-04-09 14:45  沫小豪  阅读(743)  评论(1编辑  收藏  举报