Loadrunner检查点设置

        学习LR我也和大家一样,第一个上手之作就是登录的并发,检验系统能够并发多少用户数以及并发这么多用户数所需要的时间及系统的承受能力!这也就是最简单的性能测试场景了!当时录制好脚本并参数化用户名和密码后,插入集合点,插入事务后调试脚本是没有问题的,就开始设置场景了。我用50个虚拟用户并发场景执行成功,虚拟用户数全部通过,并且没有错误事务产生,但我在Tomcat的控制台发现,有用户登录是失败的,这是怎么回事呢?后来我就用登录失败的用户手工登录系统确实无法登录成功,报:"该用户已登录,请勿重复登录!",这个是我们系统设定的,别的机器上登录了这个用户,另外一台机器就不能再登录这个用户了。这时我加入了一些系统不存在的用户名,执行脚本也没有报错,这就说明脚本确实有问题。重新录制了几次都是这样结果。后来上51testing查找到了该原因,是没有插入检查点导致的!LoadRunner以用户名为角色向服务器发送一个登陆请求,却不会判断请求的返回消息是什么,只要有返回,即使这是个拒绝登陆的返回,LoadRunner也认为这个用户名登陆成功了,其实这个用户名登录是失败的。所以在登录或者其他有重要页面跳转的地方,很有必要做检查点。我根据大虾的方法插入了Web_find检查点并且在设置中打开"图像和文本检查"的功能,再次执行脚本结果报错了,原因是我加入的虚拟用户名不存在导致的,执行场景后发现,虚拟用户有失败数,事务也有失败数,达到了预期的结果!也证明了检查点在LR中确实很重要!

       

        现在我就详细的介绍下LR中的四种常用检查点函数:Web_find()、Web_reg_find()、Web_image_check()和Web_global_verification()。


         1、web_find()

           原型:    int web_find( const char *StepName, <Attributes and Specifications list>, char *searchstring, LAST ); 

           说明:    web_find函数主要在HTML页面中查找某个特定的文本字符串.该函数现在很少使用,使用web_reg_find取代了它

           这个函数功能仅仅在HTML-based recorded scripts( see Recording Options-->Recording tab ).当HTML请求完成后才去查询内容效率不如web_reg_find。

           注意:    web_find 功能不支持运行在HTTP或Wireless Session Protocol(WSP) 回放模式。


          example1:

           web_url("index.html",
                           "URL=http://server1/",
                           "TargetFrame=",
                           LAST );

            web_find("Text Check",
                               "RightOf=Go to",
                               "LeftOf=page",
                               "What=Home",
                               LAST );


      2、Web_reg_find()

         原型:int web_reg_find( const char *attribute_list, LAST ); 

         说明:该函数功能主要是为查询某个文本字符串注册一个请求,要在action function之前。像web_url。

        

Attribute List
The attributes are passed in Name=Value pairs, for example: "Text= string ". Either Text, or TextPfx and TextSfx is required. The rest of the attributes are optional.

Text: The text string to search for. Text is a non–empty, null–terminated character string. You can further customize your search by using text flags.

Text searches for a known string. TextPfx and TextSfx are used when the string is not known in advance, but you know what strings will precede and follow it. For example, when a user is issued a user name, the server may return "Your new user name is <user name>". The user name changes, but to confirm that a name was issued it is sufficient to confirm that there is some string preceded by "Your new user name is " and followed by a ".".

You must specify the following two attributes if you do not specify Text. You can further customize your search by using text flags with these attributes.

TextPfx: The left boundry for the search. This is the text immediately preceding the text string for which you are searching.

TextSfx: The right boundry for the search. This is the text immediately following the text string for which you are searching.

Search: The scope of the search—where to search for the string. The possible values are Headers (search only the headers), Body (search only the Body data), Noresource (search only the HTML body, excluding headers and resources), or ALL (search body , headers, and resources). The default value is BODY.

SaveCount: The number of matches that were found, stored in a parameter.

The SaveCount attribute assigns the number of matches that were found to a parameter. To use this attribute, specify "SaveCount=param". When the check is performed, param is assigned a null–terminated string representing a numerical value.

When the SaveCount argument is used, and the Fail argument is not used, the check does not fail whether the text is found or not. To check whether the text has been found, examine the value of the SaveCount parameter. If it is "0", the string was not found.

If both SaveCount and Fail are used, the Fail handling option specified works together with the SaveCount. Thus, if SaveCount is used with "Fail=NotFound" and the text is found, the SaveCount parameter is assigned the number of occurrences and the check succeeds. If the text is not found, the SaveCount parameter is assigned "0" and the check fails. Of course, if the text is not found and "Fail=NotFound" has been specified, the value "0" of the parameter is only useful if the run–time setting Continue on error is selected.


The value assigned to the parameter is retained between iterations until the first action function following the web_reg_find of the next iteration. Once the script perfoms the first action function following the web_reg_find of the next iteration, the count is updated. Alternatively, you can use the lr_save_string function to change the value of the parameter at the end of the current interation—for example, with lr_save_string("0", "Count").

Fail: The handling method that sets the condition under which the check fails.


Fail can be either "Found" or "NotFound". The default is NotFound.

"Fail=NotFound" indicates that an error occurs when the text is not found. You use NotFound when searching for the text you expect to find if the Web request succeeds.

"Fail=Found " indicates that the check fails when the text is found. You might use Found, for example, searching for the word "Error". If you find "Error", the Web request did not succeed, and you want the check to fail.

When "Fail = Found" is specified with TextPfx and TextSfx and the left and right boundaries are found more than once, each match is issued as an error up to the maximum number of errors configured in the Run-Time Settings > Preferences > Advanced Options. Subsequent matches are logged as informational messages


For information about using Fail with SaveCount, see SaveCount

          Example1:

          在此例子中,web_reg_find查找文本字符串“Welcome”,如果该字符串没有搜索到,脚本将出现错误同时停止执行。

         web_url("MercuryWebTours",

                         "URL=http://localhost/MercuryWebTours/",

                         "Resource=0",

                         "RecContentType=text/html",

                         "Referer=",

                         "Snapshot=t1.inf",

                         "Mode=HTML", LAST );

// Set up check for successful login by looking for "Welcome"

               web_reg_find("Text=Welcome", LAST );

// Now log in

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 );  

     

          Example2:

          还是基于例子1,但是由于使用了Save Count,脚本执行错误时不会halt住,取而代之的是,脚本执行时会有错误提示。

           // Run the Web Tours sample

             web_url("MercuryWebTours",

                             "URL=http://localhost/MercuryWebTours/",

                             "Resource=0",

                             "RecContentType=text/html",

                             "Referer=",

                             "Snapshot=t1.inf",

                             "Mode=HTML", LAST );

// Set up check for successful login by looking for "Welcome"

             web_reg_find("Text=Welcome", "SaveCount=Welcome_Count", LAST );

// Now log in

            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 );

// Check result

              if (atoi(lr_eval_string("{Welcome_Count}")) > 0){

                    lr_output_message("Log on successful.");

                   }

             else{

                   lr_error_message("Log on failed");

                   return(0);

                }


      example3:

        在下面例子中,web_reg_find搜索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

      

       3、Web_image_check()

         原型:int web_image_check( const char *CheckName, <List of Attributes>, <"Alt=alt"|| "Src=src">, LAST ); 

         说明:web_image_check函数在HTML页面中验证指定的图片。不管ALT还是Src或两者,都是不需要的属性。这个功能仅仅支持HTML-based脚本。

         Example:

                       web_url("index.html", "URL=http://localhost/ImagesAndMaps.html", "TargetFrame=", LAST );

                       web_image_check("Go2Venus", "Alt=Venus", LAST );

       4、Web_global_verification() 

           原型:int web_global_verification( <List of Attributes>, LAST );

           说明:这个函数主要在web pages中注册一个指定的文本字符串。

           Example:

           web_global_verification("Text/IC=Acme Company", "Fail=NotFound", "ID=FindAcme", LAST ); web_url("Step", "URL=...", LAST ); The log error message with the "FindAcme" ID is: Error –27127: "Text=Acme Company" not found for web_global_verification ("FindAcme")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值