Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392086
  • 博文数量: 95
  • 博客积分: 3020
  • 博客等级: 中校
  • 技术积分: 865
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-20 10:40
文章分类

全部博文(95)

文章存档

2011年(3)

2010年(8)

2009年(24)

2008年(60)

我的朋友

分类: 项目管理

2008-12-30 13:55:57

Loadrunner中的检查点函数,主要介绍两个函数:web_find()和web_reg_find()

    这两个函数均用于内容的查找,但两者也有本质的区别,具体介绍如下:

    一、web_find()函数

    该函数的作用是“在页面中查找相应的内容”,常用参数及含义如下:

web_find("web_find", //定义该查找函数的名称
        "RightOf=a", //定义查找字符的右边界 
        "LeftOf=b", //定义查找字符的左边界
       "What=name", //定义查找内容
             LAST);


使用该函数注意以下事项:

1、位置:该函数在页面内容显示出来以后,在页面中进行查找,所以只能写在要查找内容之后。

2、录制模式:该函数只能在基于HTML模式录制的脚本中进行查找。

3、必须启用内容检查选项:在runtime setting->Preferences里面,把Enable image and text check选中,否则不执行该查找函数。

4、在VB和JAVA语法中不支持该函数。

该函数有以下一个缺点:

1、执行效率较低。

2、不返回查找结果情况,如想在执行该函数后根据查找结果做进一步操作时,没有返回值可以依据。

例如:

在页面中查找“登录成功”的字符串,如果找到该字符串在日志中输出“登录成功”,如果找不到该字符串,则在日志中输出“登录失败”,此时使用该函数没有依据来做此判断,但使用web_reg_find()函数,使用它其中的SaveCount可以进行判断,具体方法我们下面介绍。

    二、web_reg_find()函数

    该函数的作用是“在缓存中查找相应的内容”,常用参数及含义如下:

web_reg_find("Search=Body", //定义查找范围 
           "SaveCount=ddd", //定义查找计数变量名称(在该函数的参数中有个“SaveCount”,该参数可以记录在缓存中查找内容出现的次数,我们可以使用该值,来判断要查找的内容是否被找到)
               "Text=aaaa", //定义查找内容
                    LAST);

例:使用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
    }
    return 0;
}

执行这个脚本,得到的结果是:
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.

阅读(3271) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~