需求:Loadrunner编写登录接口脚本
1、打开抓包工具,如Fiddler,抓包模式
2、打开浏览器,操作登录页面,成功登录
3、切换到Fiddler,找到该post请求
4、打开vugen,右键insert-new step,找到web_custom_request方法,填写请求类型:POST,填写URL:http://192.168.X.X:8005/Account/Login?,填写Body:LoginName=.......&Password=111111&Target=,勾选Record mode为HTTP,点击“确定”
5、接口脚本初步完成,根据情况,添加检查点、事务、思考时间等等,多次调试,进行场景压测就可以了!!!
代码如下:
Action()
{
lr_start_transaction("gettoken");
lr_convert_string_encoding( lr_eval_string("{username}"),LR_ENC_SYSTEM_LOCALE, LR_ENC_UTF8, "test" );
//lr_convert_string_encoding(username,LR_ENC_SYSTEM_LOCALE, LR_ENC_UTF8, "test");
//strcpy(tmp,lr_eval_string("{test}"));
//lr_save_string(tmp,"test");
web_reg_find("Fail=NotFound",
"Search=Body",
"SaveCount=",
"Text=\"result\":1",
LAST);
web_custom_request("web_custom_request",
"URL=http://192.168.x.x:8005/Account/Login?",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Mode=HTTP",
"Body=LoginName={test}&PassWord={password}&TarGet=",
LAST);
lr_end_transaction("gettoken", LR_AUTO);
return 0;
}