zoukankan      html  css  js  c++  java
  • LoadRunner函数示例:lr_paramarr_random()

      lr_paramarr_random()函数的作用为:从一个参数数组中随机抽取一个值并以字符串形式返回。其使用方式及返回方式如下:

    char * lr_paramarr_random( const char * paramArrayName); 

    该函数在某些测试场景下或许比较有用,如随机选择页面中一个下拉框中的值。

    本次测试的WEB页面源码如下:

     1 <html>
     2 <head>
     3 </head>
     4 <body>
     5 <select id="mySelect">
     6 <option>bag</option>
     7 <option>book</option>
     8 <option>apple</option>
     9 </select>
    10 
    11 </body>
    12 </html>

     将该WEB页丢到Apache进行发布。

    对应的LoadRunner脚本代码如下:

     1 Action()
     2 {
     3     char *str;
     4     web_reg_save_param(
     5         "Names",
     6         "LB=<option>",
     7         "RB=</option>
    ",
     8         "Ord=all",
     9 
    10         LAST);
    11 
    12     web_url("Test.html", 
    13         "URL=http://127.0.0.1:8080/Test.html", 
    14         "Resource=0", 
    15         "RecContentType=text/html", 
    16         "Referer=", 
    17         "Snapshot=t1.inf", 
    18         "Mode=HTML", 
    19         LAST);
    20 
    21     str = lr_paramarr_random("Names");
    22    // lr_save_string(lr_paramarr_random("Names"),"name");    通过 lr_save_string()函数,将该随机返回的参数保存到参数 ‘name' 中
    23   lr_message("the name is Error : %s",str);
    24     // lr_message("the name is : %s",lr_eval_string("{name}"));  
    25   //打印出该 'name' 参数的值
    26     return 0;
    27 }

    脚本运行的日志如下:

     1 Starting action Action.
     2 Action.c(4): Registering web_reg_save_param was successful      [MsgId: MMSG-26390]
     3 Action.c(12): Notify: Saving Parameter "Names_1 = bag".
     4 Action.c(12): Notify: Saving Parameter "Names_2 = book".
     5 Action.c(12): Notify: Saving Parameter "Names_3 = apple".
     6 Action.c(12): Notify: Saving Parameter "Names_count = 3".
     7 Action.c(12): web_url("Test.html") was successful, 232 body bytes, 308 header bytes      [MsgId: MMSG-26386]
     8 Action.c(22): Notify: Parameter Substitution: parameter "Names_count" =  "3"
     9 Action.c(22): Notify: Parameter Substitution: parameter "Names_2" =  "book"
    10 Action.c(22): Notify: Saving Parameter "name = book".
    11 Action.c(24): Notify: Parameter Substitution: parameter "name" =  "book"
    12 the name is : book
    13 Ending action Action.

    脚本解释:

    1、运行完web_url()函数后,web_reg_save_param()函数把三个参数的值保存在了 ‘Names’ 参数数组中。

    2、lr_paramarr_random()函数从 Names 参数数组中,随机抽取一个值并以字符串的形式返回(本次返回的值是 'book' )

    3、打印输出该值

  • 相关阅读:
    .NET Page对象各事件执行顺序
    允许webservice远程在ie里面调用配置方法
    sea.js模块化编程
    atom配置web开发环境
    CSS代码规范
    HTML DOM总结
    10分钟写一个markdown编辑器
    sea.js详解
    圣杯布局 双飞翼布局
    Spring学习(1)
  • 原文地址:https://www.cnblogs.com/zhm450/p/3723984.html
Copyright © 2011-2022 走看看