loadrunner常用检查函数

web_find      ---在html页面中搜索文本字符串

int  web_find( const char * StepName, < Attributes and Specifications list>, char * searchstring, LAST ); 
 
StepName:步骤名称,必选
Attributes and Specifications list:属性列表,可选
    expect:定义返回成功的标准,found(默认)-表示找到字符串返回成功,notfound-表示未找到字符串返回成功
    Matchcase:是否区分大小写,yes-表示区分大小写,no(默认)-表示不区分大小写
    report:定义结果报告的内容,success-只包含成功,failure-只包含失败,always(默认)-包含所有
    onfailure=abort:失败则终止脚本运行
    RightOf:从指定字符串的右边开始查找
    LeftOf:从指定字符串的左边开始查找
 
Runtime Settings ->Preferences->Checks   勾选Enable Image and text check
脚本一:

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", //定义查找计数变量名称
"Text=aaaa", //定义查找内容
LAST);
使用该函数注意以下事项:
 
1、 位置
 
该函数写在要查找内容的请求之前,通常情况下写在如下六个函数之前:
Web_castom_request();
web_image();
web_link();
web_submit_data();
web_submit_form();
web_url()
2、 使用技巧
在该函数的参数中有个“SaveCount”,该参数可以记录在缓存中查找内容出现的次数,我们可以使用该值,来判断要查找的内容是否被找到,下面举个例子来说明:(引用LR的帮助中的例子)
 
// Run theWebTours sample
web_url("MercuryWebTours",
"URL=http://localhost/MercuryWebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
// Set up check for successful login by looking for "Welcome"
web_reg_find("Text=Welcome",
"SaveCount=Welcome_Count",
LAST);
 
// Now log in
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username", "Value=jojo", ENDITEM,
"Name=password", "Value=bean", ENDITEM,
"Name=login.x", "Value=35", ENDITEM,
"Name=login.y", "Value=14", ENDITEM,
LAST);
// Check result
if (atoi(lr_eval_string("{Welcome_Count}")) > 0){ //判断如果Welcome字符串出现次数大于0
lr_output_message("Log on successful."); }//在日志中输出Log on successful
else{ //如果出现次数小于等于
lr_error_message("Log on failed"); //在日志中输出Log on failed
return(0);
}
我觉得这个方法非常有用,我们可以举一反三,应用到我们实际的项目中
三、插入函数的方法
 
1、 手工写入,在需要插入函数的位置手工写入该函数

2、 光标停留在要插入函数的位置,在INSERT菜单中,选择new step,在列表中选择或查找要插入的函数,根据提示填写必要的参数
3、 在tree view模式下,在树状菜单中选中要插入函数的位置,右键,选择insert after或insert before,根据提示填写必要的参数
四、总结
1、 这两个函数函数类型不同,WEB_FIND是普通函数,WEB_REG_FIND是注册函数
 
2、 WEB_FIND使用时必须开启内容检查选项,而WEB_REG_FIND则不没有此限制
 
3、 WEB_FIND只能只用在基于HTML模式录制的脚本中,而WEB_REG_FIND没有此限制
4、 WEB_FIND是在返回的页面中进行内容查找,WEB_REG_FIND是在缓存中进行查找
 
5、 WEB_FIND在执行效率上不如WEB_REG_FIND

猜你喜欢

转载自www.cnblogs.com/youyouyunduo/p/11829170.html