性能测试学习 第六课
Posted allbluexoxo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了性能测试学习 第六课相关的知识,希望对你有一定的参考价值。
1、完成(注册,登录,重置支付密码,下订单,支付订单,获取订单列表)
2、下订单备注信息用中文(lr_convert_string_encoding)进行处理
3、web_convert_param对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);
}
//下订单备注信息用中文(lr_convert_string_encoding)进行处理
lr_convert_string_encoding("商品备注",NULL,"utf-8","remark");
lr_save_string(lr_eval_string("{remark}"),"remark_str");
//关联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;
}
以上是关于性能测试学习 第六课的主要内容,如果未能解决你的问题,请参考以下文章
第六课-第三讲06_03_bash脚本编程之五 字符串测试及for循环