您的位置:首页 > 其它

LoadRunner函数详解之web_reg_find

2015-08-13 17:57 330 查看
定义:在HTML页面查询指定的文本字符串

函数形式:web_reg_find( const char *attribute_list, LAST );



示例1:查询字符串“Welcome”,如果该字符串未被查找到,则函数检查失败,脚本停止执行

web_url("MercuryWebTours",
"URL=http://localhost/MercuryWebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST );
web_reg_find("Text=Welcome",
LAST );
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 );


示例2:与示例1类似,但由于SaveCount参数被使用,因此脚本在检查失败时将继续执行后续脚本

web_url("MercuryWebTours",
"URL=http://localhost/MercuryWebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST );

web_reg_find("Text=Welcome",
"SaveCount=Welcome_Count",
LAST );

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 );

if (atoi(lr_eval_string("{Welcome_Count}")) > 0){
lr_output_message("Log on successful.");
}
else{
lr_error_message("Log on failed");
return(0);
}


示例3:查询字符串“Error”,如果文本字符串被查找到,则函数检查失败,脚本停止执行。

web_reg_find("Text/IC=Error", "Fail=Found", LAST );
web_url("Step", "URL=...", LAST );


示例4:查找字符串“ABC”,如果文本字符串未被查找到,则脚本执行Action A;如果文本字符串被查找到1次或多次,则脚本执行Action B。

web_reg_find("Text=ABC", "SaveCount=abc_count", LAST );
web_url("Step", "URL=...", LAST );
if (strcmp(lr_eval_string("{abc_count}"), "0") == 0)
Action A
else
Action B
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: