LoadRunner—常用函数
lr_save_string( const char *param_value, const char *param_name);
将param_value值保存到param_name变量中(赋值操作)
lr_eval_string( const char *instring );
返回脚本中的一个参数当前的值(取值操作)
atoi( const char *string );
将字符串转换成数字
lr_output_message
输出信息
lr_paramarr_random(const char * paramArrayName)
从参数数组中随机取一个值
LoadRunner数据交互图
LoadRunner—检查点+事物判断实践
脚本如下~
Action()
{
web_set_max_html_param_len("1024");
/* Registering parameter(s) from source task id 3
// {JSESSIONID2} = "27C9A6FAA6FA9D92E13DBD466B03FB1D"
// */
web_reg_save_param("JSESSIONID2",
"LB/IC=jsessionid=",
"RB/IC=\"",
"Ord=1",
"Search=body",
"RelFrameId=1",
LAST);
web_url("userAction_loginUI.action",
"URL=http://localhost:8080/TestOA/userAction_loginUI.action",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=style/blue/images/login_bg.gif", ENDITEM,
"Url=style/blue/images/login.gif", ENDITEM,
LAST);
web_submit_data("userAction_login.action;jsessionid=27C9A6FAA6FA9D92E13DBD466B03FB1D",
"Action=http://localhost:8080/TestOA/userAction_login.action;jsessionid={JSESSIONID2}",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/userAction_loginUI.action",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=loginName", "Value=admin", ENDITEM,
"Name=password", "Value=1234", ENDITEM,
"Name=x", "Value=52", ENDITEM,
"Name=y", "Value=22", ENDITEM,
EXTRARES,
"Url=style/blue/images/head2_bg.gif", "Referer=http://localhost:8080/TestOA/homeAction_top.action", ENDITEM,
"Url=style/blue/images/menu_btn_bg.gif", "Referer=http://localhost:8080/TestOA/homeAction_left.action", ENDITEM,
"Url=style/blue/images/top_bg.gif", "Referer=http://localhost:8080/TestOA/homeAction_top.action", ENDITEM,
LAST);
//关联函数放在使用之前
web_reg_save_param("fids",
"LB=forumAction_show.action?id=",
"RB=\"",
"Ord=all",
LAST);
web_url("论坛",
"URL=http://localhost:8080/TestOA/forumAction_list.action",
"TargetFrame=right",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/homeAction_left.action",
"Snapshot=t3.inf",
"Mode=HTML",
EXTRARES,
"Url=style/blue/images/title_bg.gif", ENDITEM,
"Url=style/blue/images/inputPageHeadBg.gif", ENDITEM,
"Url=style/blue/images/title_bg_head.gif", ENDITEM,
"Url=style/blue/images/title_bg_end.gif", ENDITEM,
LAST);
//使用关联函数的参数,放在请求之后
//随机从关联函数保存下来的web参数数组中去一个值
//把取到的随机c语言参数转换为web参数
srand(time(NULL));//设置一个当前时间戳为随机数的种子,这样可以避免随机值每次去到同样的值
lr_save_string(lr_paramarr_random("fids"),"fid");
web_url("技术交流",
"URL=http://localhost:8080/TestOA/forumAction_show.action?id={fid}",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/forumAction_list.action",
"Snapshot=t4.inf",
"Mode=HTML",
EXTRARES,
"Url=style/blue/images/pageSelector_bg.gif", "Referer=http://localhost:8080/TestOA/forumAction_show.action?id={fid}", ENDITEM,
LAST);
web_url("publishNewTopic.png",
"URL=http://localhost:8080/TestOA/topicAction_addUI.action?forumId={fid}",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/forumAction_show.action?id={fid}",
"Snapshot=t5.inf",
"Mode=HTML",
LAST);
web_url("fckeditor.html",
"URL=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/topicAction_addUI.action?forumId={fid}",
"Snapshot=t6.inf",
"Mode=HTML",
EXTRARES,
"Url=../fckconfig.js", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=js/fckeditorcode_ie.js", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=../myconfig.js", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=lang/zh-cn.js", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/fck_editor.css", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/images/toolbar.collapse.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/images/toolbar.expand.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/images/toolbar.buttonarrow.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/images/toolbar.start.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/fck_strip.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=../fckstyles.xml", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
LAST);
web_reg_find("Search=All",
"SaveCount=find_cnt",
"Text=测试关联发帖内容{content}",
LAST);
lr_start_transaction("post");
web_submit_data("topicAction_add.action",
"Action=http://localhost:8080/TestOA/topicAction_add.action",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/topicAction_addUI.action?forumId={fid}",
"Snapshot=t7.inf",
"Mode=HTML",
ITEMDATA,
"Name=forumId", "Value={fid}", ENDITEM,
"Name=title", "Value=测试关联发帖标题{title}", ENDITEM,
"Name=content", "Value=测试关联发帖内容{content}", ENDITEM,
"Name=x", "Value=35", ENDITEM,
"Name=y", "Value=5", ENDITEM,
LAST);
//先把检查点函数保存的find_cnt参数转化为c语言参数
// 然后把字符串数值转化为整型数值yi
// 最后进行比较,判断如果大于0事务成功,否则失败
if(atoi(lr_eval_string("{find_cnt}"))>0){
lr_end_transaction("post", LR_PASS);
}else{
lr_end_transaction("post", LR_FAIL);
}
return 0;
}
运行结果如下~