专注于软件性能测试与自动化测试的学习与应用

Loadrunner检查点小结

上一篇 / 下一篇  2011-06-11 12:04:01 / 个人分类:LoadRunner

******非原创*****

Loadrunner的检查点有三种:Web_find、Web_reg_find和Web_image_check。至于为什么要用检查点可以用个小例子做个测试,例如一个登陆脚本登陆的账号为123456,密码为123456,可以正确登陆,当把账号或密码改掉再执行,发现脚本并没有报错,也顺利执行下来了。原因是什么呢 ?Loadrunner以用户角色向服务器发送一个登陆请求,却不会判断请求的返回消息是什么,只要有返回,即使这是个拒绝登陆的返回,Loadrunner也认为登陆成功了。所以在登录或者其他有重要页面跳转的地方,很有必要做检查点。
 
在脚本里面加检查点,基本不影响性能,有的人说在做场景压力测试时要把检查点代码屏蔽,我觉得没什么必要。

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请求脚本后面),下面是在手册上对这个函数的限制描述:
 
The web_find function searches an HTML page for a specified text string. web_find is deprecated. It has been replaced with web_reg_find.
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脚本后面做如下的检查点:
 
web_find("web_find","What=Don't forget to sign off when you're done!",LAST);

运行脚本结果如下:

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]
 
也可以这么增加:
 
web_find("web_find","RightOf=Don't forget to s","LeftOf=gn off when you're done!","What=i",LAST);

运行脚本结果如下:

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()的返回值01表示web_reg_find()是否注册成功,并不代表查找的内容是否存在,也就是说无论查找的文本内容是否存在,都返回0。它是从返回的缓冲区扫描而不是在接收的页面中查找。这是比web_find更高效的一个函数。web_reg_save_param也是注册类函数,需要放到请求的页面之前,而且查找的内容是服务器返回的缓冲数据中查找,所以查找内容应该看html源代码的内容。
下面同样做两个例子:


例1:
web_reg_find("Text=sign",LAST);

运行脚本结果如下:

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部分只要相对路径就可以了。
---------

TAG:

 

评分:0

我来说两句

cow

cow

个人主要专注于性能测试与自动化测试方向的学习与应用

日历

« 2024-04-25  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 12849
  • 日志数: 13
  • 建立时间: 2011-03-08
  • 更新时间: 2011-06-12

RSS订阅

Open Toolbar