loadrunner传form表单,用web_submit_data函数。

Action()
{
// lr_start_transaction("hp_homepage");
// web_url("hp_homepage","url=http://127.0.0.1:1080/WebTours/",LAST);
// lr_end_transaction("hp_homepage", LR_AUTO); //web_reg_save_param("userSession","LB=name=userSession value=","RB=>","Search=body",LAST);
web_reg_save_param_ex("ParamName=userSession","LB=name=userSession value=","RB=>",SEARCH_FILTERS,"Scope=body",LAST); lr_start_transaction("hp_webtours");
web_url("hp_webtours","url=http://127.0.0.1:1080/WebTours/nav.pl?in=home",LAST);
lr_end_transaction("hp_webtours", LR_AUTO); lr_error_message("userSession=%s",lr_eval_string("{userSession}")); web_reg_save_param("result","LB=<frame src=","RB=?intro=true","Search=body",LAST);
//web_reg_save_param("result","LB=login.pl?intro=","RB= ","Search=body",LAST);
//判断事物的时候和true比较,if(strcmp(lr_eval_string("{result}"),"true")==0) lr_start_transaction("login");
web_submit_data("login",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=",
"Snapshot=t7.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession","Value={userSession}",ENDITEM,
"Name=username","Value=jojo",ENDITEM,
"Name=password","Value=bean",ENDITEM,
"Name=login.x","Value=41",ENDITEM,
"Name=login.y","Value=8",ENDITEM,
"Name=login","Value=Login",ENDITEM,
"Name=JSFormSubmit","Value=off",ENDITEM,
LAST );
//系统自动判断写为:lr_end_transaction("login", LR_AUTO);
if(strcmp(lr_eval_string("{result}"),"login.pl")==0)//一般情况下,get请求不需要检查是否成功。
{
lr_end_transaction("login", LR_PASS);
lr_error_message("log succes");
}
else{
lr_error_message("log fail");
lr_end_transaction("login", LR_FAIL);
lr_error_message("log fail");
}
return 0;
}

  

05-08 15:40