loadrunner常用检查函数
web_find ---在html页面中搜索文本字符串
Action()
{
web_custom_request("baidu_request",
"URL=http://www.guanggoo.com/t/48529#reply3",
"Method=GET",
"TargetFrame=",
"Resource=0",
"Referer=",
"Body=",
LAST);
web_find("web_find",
//期望返回成功的结果是找到字符串,因当前页面包含要查找的字符串,故返回结果是成功
"expect=found",
//当前页面中查找字符串"sayno"
"What=sayno",
LAST);
web_find("web_find",
//期望返回成功的结果是找到字符串,因当前页面包含要查找的字符串,故返回结果是成功
"expect=found",
//当前页面中查找字符串"sayyes"
"What=sayyes",
LAST);
return 0;
}
运行结果:
Action.c(12): "web_find" successful. 2 occurrence(s) of "sayno" found (RightOf="", LeftOf="") [MsgId: MMSG-27196]
Action.c(12): web_find was successful [MsgId: MMSG-26392]
Action.c(19): web_find started [MsgId: MMSG-26355]
Action.c(19): Error -27195: "web_find" failed. 0 occurrence(s) of "sayyes" found (RightOf="", LeftOf="") [MsgId: MERR-27195]
Action.c(19): web_find highest severity level was "ERROR" [MsgId: MMSG-26391]
web_reg_find ---注册函数,在下面请求中搜索文本字符串
web_reg_find("Search=Body", //定义查找范围
"SaveCount=ddd", //定义查找计数变量名称
LAST);
Web_castom_request();
web_image();
2、 使用技巧
在该函数的参数中有个“SaveCount”,该参数可以记录在缓存中查找内容出现的次数,我们可以使用该值,来判断要查找的内容是否被找到,下面举个例子来说明:(引用LR的帮助中的例子)
web_url("MercuryWebTours",
"URL=http://localhost/MercuryWebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
web_reg_find("Text=Welcome",
"SaveCount=Welcome_Count",
LAST);
web_submit_form("login.pl",
"Snapshot=t2.inf",
"Name=login.x", "Value=35", ENDITEM,
if (atoi(lr_eval_string("{Welcome_Count}")) > 0){ //判断如果Welcome字符串出现次数大于0
lr_output_message("Log on successful."); }//在日志中输出Log on successful
}
我觉得这个方法非常有用,我们可以举一反三,应用到我们实际的项目中
2、 光标停留在要插入函数的位置,在INSERT菜单中,选择new step,在列表中选择或查找要插入的函数,根据提示填写必要的参数
1、 这两个函数函数类型不同,WEB_FIND是普通函数,WEB_REG_FIND是注册函数