性能测试学习03_lr(fiddler+关联函数)

1、fiddler完成小飞机(访问首页,登录)  

Action()
{ 
 web_url("web_url",
   "URL=http://127.0.0.1:1080/webtours/",
   "TargetFrame=",
   "Resource=0",
   "Referer=",
   "Mode=HTML",
   LAST);
   
 lr_start_transaction("登录");

 
 web_submit_data("web_submit_data",
     "Action=http://127.0.0.1:1080/webtours/login.pl",
     "Method=POST",
     "TargetFrame=",
     "RecContentType=text/html",
     "Referer=http://127.0.0.1:1080/webtours/nav.pl?in=home",
     "Mode=HTML",
     ITEMDATA,
     "Name=userSession", "Value={usersession}", ENDITEM,
     "Name=username", "Value=jojo", ENDITEM,
     "Name=password", "Value=bean", ENDITEM,
     "Name=login.x", "Value=44", ENDITEM,
     "Name=login.y", "Value=15", ENDITEM,
     "Name=JSFormSubmit", "Value=off", ENDITEM,
     LAST );

 
lr_end_transaction("登录", LR_AUTO);

 

2、使用关联函数(web_reg_save_param)成功登录

  关联的思路:

  1)确定哪个值需要关联

  2)打开日志,日志的级别调整从服务器返回

  3)回放脚本

  4)在日志里面查找我们关联的关键字

  5)在日志里面双击这一行值

  6)在脚本里面光标停留的地方插入关联函数

  7)再把这个参数名称变成动态的变量({参数名称})

3、脚本加上(检查点,if判断)完善脚本

  Action()
{

    web_reg_save_param("usersession",
        "LB=name=userSession value=",
        "RB=>\n",
        LAST);

 web_url("web_url",
   "URL=http://127.0.0.1:1080/webtours/",
   "TargetFrame=",
   "Resource=0",
   "Referer=",
   "Mode=HTML",
   LAST);


     web_reg_find("Search=All",
        "SaveCount=user_name_count",//jojo出现的次数
        "Text={username}",//文本查找的信息
        LAST);  

 lr_start_transaction("登录");

 web_submit_data("web_submit_data",
     "Action=http://127.0.0.1:1080/webtours/login.pl",
     "Method=POST",
     "TargetFrame=",
     "RecContentType=text/html",
     "Referer=http://127.0.0.1:1080/webtours/nav.pl?in=home",
     "Mode=HTML",
     ITEMDATA,
     "Name=userSession", "Value={usersession}", ENDITEM,
     "Name=username", "Value=jojo", ENDITEM,
     "Name=password", "Value=bean", ENDITEM,
     "Name=login.x", "Value=0", ENDITEM,
     "Name=login.y", "Value=0", ENDITEM,
     "Name=JSFormSubmit", "Value=off", ENDITEM,
     LAST );

//lr_end_transaction("登录", LR_AUTO);

    if(atoi(lr_eval_string("{user_name_count}"))>=1)
    {
        lr_end_transaction("登录",LR_PASS);
        lr_output_message("登录成功,用户名:%s",lr_eval_string("{username}"));
    }
    else
    {
        lr_end_transaction("登录",LR_FAIL);
    }


     web_reg_find("Search=All",
        "SaveCount=advanceDiscount",//jojo出现的次数
        "Text=advanceDiscount",//文本查找的信息
        LAST);
    lr_start_transaction("选择航班1");

 web_submit_data("选择航班1",
     "Action=http://127.0.0.1:1080/webtours/reservations.pl",
     "Method=POST",
     "TargetFrame=",
     "RecContentType=text/html",
     "Referer=http://127.0.0.1:1080/webtours/reservations.pl?page=welcome",
     "Mode=HTML",
     ITEMDATA,
     "Name=advanceDiscount", "Value=0", ENDITEM,
     "Name=depart", "Value=Denver", ENDITEM,
     "Name=departDate", "Value=04/09/2019", ENDITEM,
     "Name=arrive", "Value=Denver", ENDITEM,
     "Name=returnDate", "Value=04/10/2019", ENDITEM,
     "Name=numPassengers", "Value=1", ENDITEM,
     "Name=seatPref", "Value=None", ENDITEM,
     "Name=seatType", "Value=Coach", ENDITEM,
     "Name=findFlights.x", "Value=55", ENDITEM,
     "Name=findFlights.y", "Value=13", ENDITEM,
     "Name=.cgifields", "Value=roundtrip", ENDITEM,
     "Name=.cgifields", "Value=seatType", ENDITEM,

     LAST );

    //lr_end_transaction("选择航班1", LR_AUTO);
    if(atoi(lr_eval_string("{advanceDiscount}"))>=1)
    {
        lr_end_transaction("选择航班1",LR_PASS);
    }
    else
    {
        lr_end_transaction("选择航班1",LR_FAIL);
    }


    lr_start_transaction("选择航班2");

 web_submit_data("选择航班2",
     "Action=http://127.0.0.1:1080/webtours/reservations.pl",
     "Method=POST",
     "TargetFrame=",
     "RecContentType=text/html",
     "Referer=http://127.0.0.1:1080/webtours/reservations.pl",
     "Mode=HTML",
     ITEMDATA,
     "Name=outboundFlight", "Value=000;0;04/09/2019", ENDITEM,
     "Name=numPassengers", "Value=1", ENDITEM,
     "Name=advanceDiscount", "Value=Coach", ENDITEM,
     "Name=seatType", "Value=0", ENDITEM,
     "Name=seatPref", "Value=None", ENDITEM,
     "Name=reserveFlights.x", "Value=41", ENDITEM,
     "Name=reserveFlights.y", "Value=8", ENDITEM,
     LAST );
 
    lr_end_transaction("选择航班2", LR_AUTO);


    web_reg_find("Search=All",
        "SaveCount=firstName_count",
        "Text=firstName",
        LAST);

    lr_start_transaction("付款说明");

 web_submit_data("付款说明",
     "Action=http://127.0.0.1:1080/webtours/reservations.pl",
     "Method=POST",
     "TargetFrame=",
     "RecContentType=text/html",
     "Referer=http://127.0.0.1:1080/webtours/reservations.pl",
     "Mode=HTML",
     ITEMDATA,
     "Name=firstName", "Value=Joseph", ENDITEM,
     "Name=lastName", "Value=Marshall", ENDITEM,
     "Name=address1", "Value=234 Willow Drive", ENDITEM,
     "Name=address2", "Value=San Jose/CA/94085", ENDITEM,
     "Name=pass1", "Value=Joseph Marshall", ENDITEM,
     "Name=creditCard", "Value=", ENDITEM,
     "Name=expDate", "Value=", ENDITEM,
     "Name=numPassengers", "Value=1", ENDITEM,
     "Name=seatType", "Value=Coach", ENDITEM,
     "Name=seatPref", "Value=None", ENDITEM,
     "Name=outboundFlight", "Value=000;0;04/09/2019", ENDITEM,
     "Name=advanceDiscount", "Value=0", ENDITEM,
     "Name=JSFormSubmit", "Value=off", ENDITEM,
     "Name=buyFlights.x", "Value=37", ENDITEM,
     "Name=buyFlights.y", "Value=7", ENDITEM,
     "Name=.cgifields", "Value=saveCC", ENDITEM,
     LAST );
 
    //lr_end_transaction("付款说明", LR_AUTO);
    if(atoi(lr_eval_string("{firstName_count}"))>=1)
    {
        lr_end_transaction("付款说明1",LR_PASS);
    }
    else
    {
        lr_end_transaction("付款说明",LR_FAIL);
    }

}

 

 

 

4、XX贷()完成(登录,投标(投标中要用到关联)用户名:13825161923  密码: lemon123

   可以进行投标,但未进行关联

 

 Action()
{

lr_save_string("请填写你的IP", "IP");
web_reg_find("Search=All",
    "SaveCount=pass_count",
    "Text=登录成功",
    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);
if(atoi(lr_eval_string("{pass_count}"))>=1)
 {
    lr_end_transaction("登录",LR_PASS);
 }
else
 {
    lr_end_transaction("登录",LR_FAIL);
 }

    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/13306.html",
     "Mode=HTML",
     ITEMDATA,
     "Name=id", "Value=13306", ENDITEM,
     "Name=val", "Value=100", ENDITEM,
     "Name=token", "Value=d/P5Ip5Nse0iebLuAYOblCoSy/p4W5Zsl/BViWo+q1k3uRVnJ4NTOM8Dd31l8ttvQawC8vYth+t0dSwDvWhOjzqG52p6ZK51RLeK5V5xURXw/R+3qRyZbo0yiUklLXsEvdJacI31NjqRK85AO4GW+lyPT4mFe0G+BAN7E+JPgI0=", ENDITEM,
     "Name=rewardValue", "Value=0", ENDITEM,
     LAST );

    lr_end_transaction("投资", LR_AUTO);
    lr_log_message("web_submit_data");

}

 

 

 

5、其他知识点

  1)调试日志设置

 2)在使用web_submit_data输入参数的时候,需要每个参数逐个复制,添加。其实可以使用web_custom_request,直接复制抓包来的body 中的参数串,可以参考博文连接https://www.cnblogs.com/qmfsun/p/4481444.html

posted @ 2019-04-07 20:22  沫小豪  阅读(430)  评论(0编辑  收藏  举报