性能测试学习06_lr(完成业务流程脚本编写)

白昼怎懂夜的黑 提交于 2020-01-03 03:07:31

1、完成(注册,登录,重置支付密码,下订单,支付订单,获取订单列表)

2、下订单备注信息用中文(lr_convert_string_encoding)进行处理

3、web_convert_param对token进行URLcode

完整升级版接口编写

支付平台脚本的整体思路:
1.先编写注册脚本,关联注册成功返回token,关联注册成功返回的code,关联注册成功返回的手机号,判断是否注册成功;
2.登录,使用注册手机号及密码进行登录,关联登录成功返回的code,判断是否登录成功;
3.重置支付密码,重置密码需要使用md5加密,关联重置支付密码成功返回的code,判断是否重置成功;
1)使用md5加密方法,右键点击Extra_Files,选择添加脚本路径,找到md5.h文件,完成添加;
2)点击globals.h,添加引入的md5.h的文件;
3)使用方法:通过简单的test脚本进行练习

   代码如下:

Action()
{    
    lr_save_string(CMd5("12345"),"payPassword"); 
    lr_output_message("本次运行结果%s:",lr_eval_string("{payPassword}"));

    return 0;
}
4.下订单操作,关联下订单返回的payId,关联下订单返回的code,判断是否下订单成功;
5.支付订单,关联支付订单返回的code,判断是否支付成功;
6.查看订单,关联查看订单返回的code,判断是否查看成功,
1)由于token在请求头中,所以需要urlcode编码关联
代码如下:
Action()
{
    
    lr_save_string("请填写你的IP", "IP");
    lr_save_string(CMd5("12345"),"payPassword");
                                               
//设置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_reg_save_param_ex(
        "ParamName=register_mobile",
        "LB=\"mobile\":\"",
        "RB=\",\"email\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );
//关联注册成功code
    web_reg_save_param_ex(
        "ParamName=register_code",
        "LB=\"code\":",
        "RB=,\"msg\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );
    
//注册
lr_start_transaction("注册");

    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\":\"1588888{mobile_num}\",\"password\":\"123456\",\"code\":\"3367\",\"platform\":\"windows\"}",
        LAST);            
//判断是否注册成功
       //strcmp(str1,str2):比较两str的大小
       if(strcmp(lr_eval_string("{register_code}"),"0")==0)
    {
       lr_end_transaction("注册",LR_PASS);
       lr_error_message("注册code:%s,注册手机:%s,token:%s",lr_eval_string("{register_code}"),lr_eval_string("{register_mobile}"),lr_eval_string("{token}"));
    }
   else
    {
       lr_end_transaction("注册",LR_FAIL);
    }

 
//关联登录成功code
    web_reg_save_param_ex(
        "ParamName=login_code",
        "LB=\"code\":",
        "RB=,\"msg\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );  
//登录
lr_start_transaction("登录");

    web_custom_request("login",
        "URL=http://{IP}/mobile/api/user/login ",
        "Method=POST",
        "TargetFrame=",
        "Resource=1",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json ",
        "Body={\"mobile\":\"{register_mobile}\",\"password\":\"123456\"}",
        LAST);
//判断是否登录成功
       //strcmp(str1,str2):比较两str的大小
       if(strcmp(lr_eval_string("{login_code}"),"0")==0)
    {
       lr_end_transaction("登录",LR_PASS);
       lr_error_message("登录code:%s",lr_eval_string("{login_code}"));
    }
   else
    {
       lr_end_transaction("登录",LR_FAIL);
    }


//关联重置支付密码的msg
web_reg_save_param_ex(
        "ParamName=resetpaywd_msg",
        "LB=\"msg\":\"",
        "RB=\",\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );
   
//关联重置支付密码成功code
    web_reg_save_param_ex(
        "ParamName=resetpaywd_code",
        "LB=\"code\":",
        "RB=,\"msg\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );

//重置支付密码
lr_start_transaction("重置支付密码");

    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\":\"{payPassword}\"}",
        LAST);
//判断是否重置支付密码成功
       //strcmp(str1,str2):比较两str的大小
       if(strcmp(lr_eval_string("{resetpaywd_code}"),"0")==0)
    {
       lr_end_transaction("重置支付密码",LR_PASS);
       lr_convert_string_encoding(lr_eval_string("{resetpaywd_msg}"),"utf-8",NULL,"resetpaywd_msg");
       lr_error_message("重置支付密码code:%s,重置支付密码msg:%s",lr_eval_string("{resetpaywd_code}"),lr_eval_string("{resetpaywd_msg}"));
    }
   else
    {
       lr_end_transaction("重置支付密码",LR_FAIL);
    }


//关联padId
    web_reg_save_param_ex(
        "ParamName=payId",
        "LB=\"payId\":\"",
        "RB=\",\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );
//关联下订单code
    web_reg_save_param_ex(
        "ParamName=addorder_code",
        "LB=\"code\":",
        "RB=,\"msg\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );
//关联下订单的msg
    web_reg_save_param_ex(
        "ParamName=addorder_msg",
        "LB=\"msg\":\"",
        "RB=\",\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );
//下订单
lr_start_transaction("下订单");

    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\":1.1,\"orders\":[{\"getTime\":1450921104000,\"goodss\":[{\"goodsId\":93,\"count\":1},{\"goodsId\":96,\"count\":1}]}],\"invoiceTitle\":\"fapiao\"}",
        LAST);
//判断是否下订单成功
       //strcmp(str1,str2):比较两str的大小
       if(strcmp(lr_eval_string("{addorder_code}"),"0")==0)
    {
       lr_end_transaction("下订单",LR_PASS);
       lr_convert_string_encoding(lr_eval_string("{addorder_msg}"),"utf-8",NULL,"addorder_msg");
       lr_error_message("下订单code:%s,订单padId:%s,下单订msg:%s",lr_eval_string("{addorder_code}"),lr_eval_string("{payId}"),lr_eval_string("{addorder_msg}"));
    }
   else
    {
       lr_end_transaction("下订单",LR_FAIL);
    }  

   
//关联支付订单code
    web_reg_save_param_ex(
        "ParamName=pay_code",
        "LB=\"code\":",
        "RB=,\"msg\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );
//支付订单
lr_start_transaction("支付订单");

    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\":\"{payPassword}\",\"platform\":3}",
        LAST);
//判断是否支付订单成功
       //strcmp(str1,str2):比较两str的大小
       if(strcmp(lr_eval_string("{pay_code}"),"0")==0)
    {
       lr_end_transaction("支付订单",LR_PASS);
       lr_error_message("支付订单code:%s,",lr_eval_string("{pay_code}"));
    }
   else
    {
       lr_end_transaction("支付订单",LR_FAIL);
    }  
   
  
//对token进行urlcode编码
    lr_save_string(lr_eval_string("{token}"),"tokenUTF8");//把token进行urlcode编码
    web_convert_param(
    "tokenUTF8",                                        //参数名称,转换后的字符串被保存在该参数            
    "SourceEncoding=PLAIN",                                //编码的数据类型HTML、URL、plain
    "TargetEncoding=URL",                                //目标数据的编码类型
    LAST );       
//关联查看订单code
    web_reg_save_param_ex(
        "ParamName=getorders_code",
        "LB=\"code\":",
        "RB=,\"msg\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        "Scope=ALL",
        LAST );
lr_start_transaction("查看订单");

//查看订单
    web_custom_request("getorders",
        "URL=http://{IP}/mobile/api/order/getorders?offset=0&token={tokenUTF8}",
        "Method=GET",
        "TargetFrame=",
        "Resource=1",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json ",
        LAST);
//判断是否查看订单成功
       //strcmp(str1,str2):比较两str的大小
       if(strcmp(lr_eval_string("{getorders_code}"),"0")==0)
    {
       lr_end_transaction("查看订单",LR_PASS);
       lr_error_message("查看订单code:%s,",lr_eval_string("{getorders_code}"));
    }
   else
    {
       lr_end_transaction("查看订单",LR_FAIL);
    }  

   return 0;
}

 预先安装(LR11:安装jdk1.6 32位,LR12:安装jdk1.7 32位),安装包在网盘里面

预习:java相关知识,用java完成md5算法加密,网上通用的,用java请求HTTP接口,提前安装idea工具(https://www.jetbrains.com/idea/download/#section=windows

Community免费版)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!