LoadRunner函数详解之web_reg_find
https://blog.csdn.net/jiang1986829/article/details/47616399
定义:在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 );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
示例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);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
示例3:查询字符串“Error”,如果文本字符串被查找到,则函数检查失败,脚本停止执行。
web_reg_find("Text/IC=Error", "Fail=Found", LAST );
web_url("Step", "URL=...", LAST );
1
2
示例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