Web_find和Web_image_check两个函数如果在脚本里面增加,需要在设置中打开“图像和文本检查”功能,该功能默认是不打开的,如果手工在脚本里面添加检查点,系统会有提示:
Action.c(43): Verification checks not enabled. web_find is skipped. See the 'Run-time settings/Preferences/Checks'
[MsgId: MMSG-27197]
下面对这三个检查点简单做一下小结:
1、Web_find
Web_find只能在html的录制模式下查找html页面文字,查找速度慢,并且要在html请求结束后才会去查找(即这个函数需要写在html请求脚本后面),下面是在手册上对这个函数的限制描述:
This function is limited to HTML-based recorded scripts (see Recording Options > Recording tab). It searches the context only after the HTML request is complete, resulting in slower execution time than web_reg_find.
The web_find function has been superseded in C Language scripts by web_reg_find, which runs faster and can be used in both HTML-based and URL-based recording. web_find is supported in C for backward compatibility. In Java and Visual Basic, it has not been superseded.
The web_find function is not supported for WAP scripts running in HTTP or Wireless Session Protocol (WSP) replay mode.
例如Loadrunner自带的订票程序在登陆后有这么一段文字描述:
Welcome, jojo, to the Mercury Tours reservation pages.
Using the menu to the left, you can search for new flights to book, or review/edit the flights already booked. Don't forget to sign off when you're done!
我们可以在对应页面的url脚本后面做如下的检查点:
运行脚本结果如下:
Action.c(43): "web_find" successful. 1 occurrence(s) of "Don't forget to sign off when you're done!" found (RightOf="", LeftOf="")[MsgId: MMSG-27196]
运行脚本结果如下:
Action.c(46): "web_find" successful. 1 occurrence(s) of "i" found (RightOf="Don't forget to s", LeftOf="gn off when you're done!")[MsgId: MMSG-27196]
这块有一点需要注意,RightOf和LeftOf并不是指右边和左边边界,而是指要查找的“i”在RightOf的右边,在LeftOf的左边。
2、Web_reg_find
Web_reg_find是注册类型函数,它本身并不执行,不能通过它的返回值来作为事务的判断条件(因为web_reg_find()的返回值0和1表示web_reg_find()是否注册成功,并不代表查找的内容是否存在,也就是说无论查找的文本内容是否存在,都返回0。它是从返回的缓冲区扫描而不是在接收的页面中查找。这是比web_find更高效的一个函数。web_reg_save_param也是注册类函数,需要放到请求的页面之前,而且查找的内容是服务器返回的缓冲数据中查找,所以查找内容应该看html源代码的内容。
下面同样做两个例子:
例1:
运行脚本结果如下:
Action.c(34): Registered web_reg_find successful for "Text=sign" (count=3)[MsgId: MMSG-26364]
例2:
利用web_reg_find创建的参数SaveCount ,作为判断条件
web_reg_find("Text=sign", "SaveCount=para_count", LAST);
web_url("Home Button",
"URL=http://127.0.0.1:1080/mercuryWebTours/welcome.pl?page=menus",
"TargetFrame=body",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=itinerary",
"Snapshot=t8.inf",
"Mode=HTML",
LAST);
if (atoi(lr_eval_string("{para_count}"))>0)
lr_output_message("Login on succesful!");
else
lr_error_message("Login on fail!");
运行脚本结果如下:
Action.c(48): Login on succesful!
在使用web_reg_find时有一点需要注意,如果抓取的是中文,不要用utf8格式,否则抓到的都是乱码,运行总是不会成功。
3、Web_image_check
这个函数比较简单,写在对应的web_ur后面即可:
web_url("Home Button",
"URL=http://127.0.0.1:1080/mercuryWebTours/welcome.pl?page=menus",
"TargetFrame=body",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=itinerary",
"Snapshot=t8.inf",
"Mode=HTML",
LAST);
web_image_check("web_image_check","src=/images/signoff.gif",LAST);
执行结果如下:
Action.c(42): "web_image_check" succeeded (1 occurrence(s) found. Alt="", Src="/images/signoff.gif")[MsgId: MMSG-27192]
Action.c(42): web_image_check was successful[MsgId: MMSG-26392]
这里说明一下对应的src可以在脚本执行后的日志里面找到,日志记录的是完整路径,src部分只要相对路径就可以了。