转-LR检查点函数
上一篇 / 下一篇 2009-07-28 08:15:09 / 个人分类:LoadRunner
这两个函数均用于内容的查找,但两者也有本质的区别,具体介绍如下:
一、web_find()函数
该函数的作用是“在页面中查找相应的内容”,常用参数及含义如下:
|
使用该函数注意以下事项:
1、位置:该函数在页面内容显示出来以后,在页面中进行查找,所以只能写在要查找内容之后。
2、录制模式:该函数只能在基于HTML模式录制的脚本中进行查找。
3、必须启用内容检查选项:在runtime setting->Preferences里面,把Enable image and text check选中,否则不执行该查找函数。
4、在VB和JAVA语法中不支持该函数。
该函数有以下一个缺点:
1、执行效率较低。
2、不返回查找结果情况,如想在执行该函数后根据查找结果做进一步操作时,没有返回值可以依据。
例如:
在页面中查找“登录成功”的字符串,如果找到该字符串在日志中输出“登录成功”,如果找不到该字符串,则在日志中输出“登录失败”,此时使用该函数没有依据来做此判断,但使用web_reg_find()函数,使用它其中的SaveCount可以进行判断,具体方法我们下面介绍。
二、web_reg_find()函数
该函数的作用是“在缓存中查找相应的内容”,常用参数及含义如下:
|
例:使用LR自带的例子
Action()
{
web_url("mercuryWebTours",
"URL=http://127.0.0.1:1080/mercuryWebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_think_time(4);
web_reg_find("Text=welcome","SaveCount=ddd",
LAST);
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username","Value={NewParam}",ENDITEM,
"Name=password","Value={NewParam_1}",ENDITEM,
"Name=login.x","Value=42",ENDITEM,
"Name=login.y","Value=9",ENDITEM,
LAST);
lr_think_time(14);
web_image("SignOff Button",
"Alt=SignOff Button",
"Snapshot=t3.inf",
LAST);
if(atoi(lr_eval_string("{ddd}"))>0){
lr_output_message("222222222222222222222222.");}//atoi():转换一个ASCII字符串为一个整型。lr_eval_string():是取得参数值,lrs_send("socket0", lr_eval_string("buf2"), LrsLastArg);lr_eval_string很有用,它将字符串变量buf2中的参数替换为当前的参数值并将这个字符串返回。lr_output_message(const char *format, exp1, exp2,……expn.);中文解释:lr_output_message函数将带有脚本部分的行号的消息发送到输出窗口和日志文件。
else
{
lr_error_message("55555555555555555555555");//lr_error_message(const char *format, exp1, exp2,……expn. );中文解释:lr_error_message函数将错误消息发送到输出窗口和Vuser日志文件。要发送不是特定错误消息的特殊通知,请使用lr_output_message
}
return0;
}
执行这个脚本,得到的结果是:
Virtual User Script. started
Starting action vuser_init.
Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788 [MsgId: MMSG-27143]
Run-Time Settings file: "D:\lr\b\\default.cfg" [MsgId: MMSG-27141]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(5): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/header.html" in "http://127.0.0.1:1080/mercuryWebTours/" [MsgId: MMSG-26574]
Action.c(5): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=true" in "http://127.0.0.1:1080/mercuryWebTours/" [MsgId: MMSG-26574]
Action.c(5): Found resource "http://127.0.0.1:1080/mercuryWebTours/images/mercury_logo.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/header.html" [MsgId: MMSG-26659]
Action.c(5): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/nav.pl?in=home" in "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=true" [MsgId: MMSG-26574]
Action.c(5): Detected non-resource "http://127.0.0.1:1080/MercuryWebTours/home.html" in "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=true" [MsgId: MMSG-26574]
Action.c(5): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/fma-gateway.jpg" in HTML "http://127.0.0.1:1080/MercuryWebTours/home.html" [MsgId: MMSG-26659]
Action.c(5): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/mer_login.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?in=home" [MsgId: MMSG-26659]
Action.c(5): web_url("mercuryWebTours") was successful, 52180 body bytes, 1566 header bytes [MsgId: MMSG-26386]
Action.c(15): Registering web_reg_find was successful [MsgId: MMSG-26390]
Action.c(18): Submitting form. to "http://127.0.0.1:1080/mercuryWebTours/login.pl", Target Frame="body" [MsgId: MMSG-27978]
Action.c(18): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" in "http://127.0.0.1:1080/mercuryWebTours/login.pl" [MsgId: MMSG-26574]
Action.c(18): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/login.pl?intro=true" in "http://127.0.0.1:1080/mercuryWebTours/login.pl" [MsgId: MMSG-26574]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/flights.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" [MsgId: MMSG-26659]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/itinerary.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" [MsgId: MMSG-26659]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/in_home.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" [MsgId: MMSG-26659]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/signoff.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" [MsgId: MMSG-26659]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/fma-performance-center.jpg" in HTML "http://127.0.0.1:1080/mercuryWebTours/login.pl?intro=true" [MsgId: MMSG-26659]
Action.c(18): Registered web_reg_find successful for "Text=welcome" (count=4) [MsgId: MMSG-26364]
Action.c(18): web_submit_form("login.pl") was successful, 32666 body bytes, 1649 header bytes [MsgId: MMSG-26386]
Action.c(29): Image-linking to "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=1", Target Frame="body" [MsgId: MMSG-27993]
Action.c(29): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/nav.pl?in=home" in "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=1" [MsgId: MMSG-26574]
Action.c(29): Detected non-resource "http://127.0.0.1:1080/MercuryWebTours/home.html" in "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=1" [MsgId: MMSG-26574]
Action.c(29): Retrieving data from cache for "http://127.0.0.1:1080/MercuryWebTours/home.html" [MsgId: MMSG-26558]
Action.c(29): Resource "http://127.0.0.1:1080/MercuryWebTours/images/fma-gateway.jpg" is in the cache already and will not be downloaded again [MsgId: MMSG-26655]
Action.c(29): Resource "http://127.0.0.1:1080/MercuryWebTours/images/mer_login.gif" is in the cache already and will not be downloaded again [MsgId: MMSG-26655]
Action.c(29): web_image("SignOff Button") was successful, 1985 body bytes, 577 header bytes [MsgId: MMSG-26386]
Action.c(35): 222222222222222222222222.
Ending action Action.
Ending iteration 1.
Starting iteration 2.
Starting action Action.
Action.c(5): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/header.html" in "http://127.0.0.1:1080/mercuryWebTours/" [MsgId: MMSG-26574]
Action.c(5): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=true" in "http://127.0.0.1:1080/mercuryWebTours/" [MsgId: MMSG-26574]
Action.c(5): Found resource "http://127.0.0.1:1080/mercuryWebTours/images/mercury_logo.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/header.html" [MsgId: MMSG-26659]
Action.c(5): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/nav.pl?in=home" in "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=true" [MsgId: MMSG-26574]
Action.c(5): Detected non-resource "http://127.0.0.1:1080/MercuryWebTours/home.html" in "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=true" [MsgId: MMSG-26574]
Action.c(5): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/fma-gateway.jpg" in HTML "http://127.0.0.1:1080/MercuryWebTours/home.html" [MsgId: MMSG-26659]
Action.c(5): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/mer_login.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?in=home" [MsgId: MMSG-26659]
Action.c(5): web_url("mercuryWebTours") was successful, 52176 body bytes, 1566 header bytes [MsgId: MMSG-26386]
Action.c(15): Registering web_reg_find was successful [MsgId: MMSG-26390]
Action.c(18): Submitting form. to "http://127.0.0.1:1080/mercuryWebTours/login.pl", Target Frame="body" [MsgId: MMSG-27978]
Action.c(18): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" in "http://127.0.0.1:1080/mercuryWebTours/login.pl" [MsgId: MMSG-26574]
Action.c(18): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/login.pl?intro=true" in "http://127.0.0.1:1080/mercuryWebTours/login.pl" [MsgId: MMSG-26574]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/flights.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" [MsgId: MMSG-26659]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/itinerary.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" [MsgId: MMSG-26659]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/in_home.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" [MsgId: MMSG-26659]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/signoff.gif" in HTML "http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home" [MsgId: MMSG-26659]
Action.c(18): Found resource "http://127.0.0.1:1080/MercuryWebTours/images/fma-performance-center.jpg" in HTML "http://127.0.0.1:1080/mercuryWebTours/login.pl?intro=true" [MsgId: MMSG-26659]
Action.c(18): Registered web_reg_find successful for "Text=welcome" (count=4) [MsgId: MMSG-26364]
Action.c(18): web_submit_form("login.pl") was successful, 32666 body bytes, 1649 header bytes [MsgId: MMSG-26386]
Action.c(29): Image-linking to "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=1", Target Frame="body" [MsgId: MMSG-27993]
Action.c(29): Detected non-resource "http://127.0.0.1:1080/mercuryWebTours/nav.pl?in=home" in "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=1" [MsgId: MMSG-26574]
Action.c(29): Detected non-resource "http://127.0.0.1:1080/MercuryWebTours/home.html" in "http://127.0.0.1:1080/mercuryWebTours/welcome.pl?signOff=1" [MsgId: MMSG-26574]
Action.c(29): Retrieving data from cache for "http://127.0.0.1:1080/MercuryWebTours/home.html" [MsgId: MMSG-26558]
Action.c(29): Resource "http://127.0.0.1:1080/MercuryWebTours/images/fma-gateway.jpg" is in the cache already and will not be downloaded again [MsgId: MMSG-26655]
Action.c(29): Resource "http://127.0.0.1:1080/MercuryWebTours/images/mer_login.gif" is in the cache already and will not be downloaded again [MsgId: MMSG-26655]
Action.c(29): web_image("SignOff Button") was successful, 1991 body bytes, 577 header bytes [MsgId: MMSG-26386]
Action.c(35): 222222222222222222222222.
Ending action Action.
Ending iteration 2.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
TAG:
标题搜索
日历
|
|||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
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 | 30 |
我的存档
数据统计
- 访问量: 177475
- 日志数: 90
- 建立时间: 2009-01-09
- 更新时间: 2013-03-22