LoadRunner脚本开发:参数列表和常用函数(三)

1|0一. 参数化:Design > Parameters > Parameters lists


1. Parameter Properties

  Parameter type

2. create table > edit with notepad

  Add Columns

  Add Rows

3. select 

1|1第一种方式参数化:


 

1|2 第二种方式参数化


 

 

 

 要替换某个值,需要将这个Original value变为该值

1|3Parameter type


 

Parameter type 描述
Custom 普通常规参数替换
Date/Time 日期/时间型参数,可以指定不同格式时间
File 文本型,读取.bat文件中的内容,内容可以在下面表格中编辑,可以多列,用逗号分隔
GroupName 用户所属于组(跑脚本时)
Iteration Number 迭代编号参数替换vuser的迭代编号
Load Generator Name 控制器名称
Random Number 随机数字,需要设置最大最小值,常用于一定范围内取值,或vuser执行任务的百分比分布
Table 与file文本相同
Unique Number 唯一值
User Defined Function 用户自定义函数
VuserID 用户id
xml 用于xml结构中包含的多值数据,在这个结构中,一个数组可以成为另一个数组的一部分。常用在xml服务或soap服务

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1|4参数化取值


Select next row

Sequential

顺序 按照参数化顺序,从上往下
Random 随机 从参数化数据中,随机取值
Unique 唯一 为每个虚拟用户分配一个唯一数据
Update value on Each iteration 每次迭代 每次迭代取新的值
Each occurrence 每次出现 每次参数取值都取新的值
once 一次 一条数据只被取一次

 

 

 

 

 

 

 

 

 

1|5其他


 

2|0二. custom type


 

 

 

 

 

3|0三. File:sequential_eachiteration


 

 

 

 

 

4|0四. File:sequential_echooccurrence


 

 

 

 

 

5|0五. File:unique_eachoccurrence


情况一:Abort Vuser:停止测试

 

 

 

 

 

情况二:Continue in a cyclic manner:循环取值,再重新开始新一轮的unique取值

 

 

 

 

情况三:Continue with last value:沿用最后一个值

 

 

 

 

6|0六. Group Name


 

 

 

7|0七. Iteration Number


 

 

 

8|0八. Random Number


 

 

9|0九. loadrunner事务 VS jmeter 事务


9|1jmeter事务


  没有明显的事务标识

  一般,一个取样器就算一个事务

9|2loadrunner事务


  可以显示添加事务开始和结束标识

  开始、结束事务之间请求数无限制

10|0十. 常用函数


10|1字符串处理函数


1. atoi()   字符串转为整型

2. atof()   字符串转为浮点型

3. itoa()   整型转为字符型

4. asctime()   字符串形式显示时间

5. ctime()   时间转换为本地时间

6. strcmp()   比较两个变量

7. strcpy()   复制字符串

8. strcat()   连接两个字符串

10|2其他函数


1. abs   获取数字绝对值

2. cos   余弦

3. sin   正弦

4. fopen   打开文件

5. fclose   关闭文件

6. fread   读取文件

7. fwrite   写文件

8. fscanf   格式化输入

9. fprintf   格式化输出

10. ftime   打印时间

11. gmtime   转为UTC时间

12. strftime   时间转为字符串输出

13. stricmp   不区分大小写比较

14. strlen   字符串长度

15. strlwr   字符串转为小写

16. strupr   字符串转为大写

10|3lr_函数(是C语言函数的封装,不论是什么协议都可以用)


1. commandline函数   

lr_get_atrrib_string();

 

2. database函数   

lr_db_connect();   

lr_db_disconnect();   

lr_db_executeSQLStement();   

lr_db_getValue();

 

3. infomation函数   

lr_whoami();

 

4. Message函数   

lr_error_message();   

lr_message();   

lr_log_message();   

lr_output_message();  (与lr_log_message()的区别是,不仅会在面板展示,还会写到文件中去)

 

5. run-time函数   

lr_abort();   

lr_continue_on_error();   

lr_exit();   

lr_rendezvous();   

lr_think_time();

 

6. 字符参数函数   

lr_eval_string();   

lr_paramarr_len();   

lr_save_datetime();   

lr_save_param_regexp();   

lr_save_string();

 

7. 事务函数   

lr_start_transaction();   

lr_stop_transaction();

 

8. xml函数

 

10|4web函数(是做http请求的一类函数)


1. 动作函数 

web_custom_request();   可以用作get和post

web_submit_data();

web_submit_form();

web_url();

 

2. 认证函数

3. 异步函数

4. 检查函数

web_find();

web_reg_find();

 

5. 连接函数

6. 并发组函数

7. cookie相关函数

web_add_cookie();

web_cleanup_cookie();

web_remove_cookie();

 

8. 相关函数

web_reg_save_param_ex();

web_reg_save_param_regexp();

web_set_max_html_param_len();

 

9. 数据格式函数

10. 过滤函数

11. header函数

web_add_auto_header();

web_add_header();

web_cleanup_auto_headers();

web_remove_auto_header();

web_save_header();

 

12. 代理服务器函数

13. 重播函数

web_set_option();

web_set_timeout();

 

11|0十一. 实例


Action() { //设置固定参数:前面是值,后面是参数名 lr_save_string("192.168.0.102", "host"); lr_save_string("8081", "port"); //lr_save_string("13812345678", "mobilephone"); lr_save_string("123456", "pwd"); //保存注册接口的响应结果 web_reg_save_param("register_response", "LB={", "RB=}", "Search=All", "Ord=All", LAST); //注册: member/register web_url("register", "url=http://{host}:{port}/futureloan/mvc/api/member/register?mobilephone=138{randomPhone}&pwd={pwd}", //参数化 LAST); //手动转换后输出,防止响应结果中的中文乱码 lr_convert_string_encoding(lr_paramarr_random("register_response"), "utf-8", NULL, "register_result"); //================================================================== //保存登录接口的响应结果 web_reg_save_param("login_response", "LB={", "RB=}", "Search=All", "Ord=All", LAST); //找到登录返回值 web_reg_find("Text=10001", "SaveCount=login_status", //统计10001出现的次数 LAST); //登录:member/login,不知道如何关联请求数据,这里只能用固定的mobilephone代替了 web_url("login", "url=http://{host}:{port}/futureloan/mvc/api/member/login?mobilephone=13845968970&pwd={pwd}", LAST); //手动转换后输出,防止响应结果中的中文乱码 lr_convert_string_encoding(lr_paramarr_random("login_response"), "utf-8", NULL, "login_result"); //检查结果 if(atoi(lr_eval_string("{login_status}")) == 1) { lr_output_message("************登录成功*****************"); //return 0; //如果这个地方启用,则直接结束,后面的脚本都将不再执行 } else { lr_output_message("============%d============", atoi(lr_eval_string("{login_status}"))); lr_output_message("=================登录失败===================="); return -1; //直接结束 } }

运行结果

Virtual User Script started at : 2019/11/9 15:26:52 Starting action vuser_init. Web Turbo Replay of LoadRunner 12.0.0 for Windows 2008 R2; build 2739 (Nov 30 2014 23:13:05) [MsgId: MMSG-27143] Run mode: HTML [MsgId: MMSG-26993] Run-Time Settings file: "C:\Users\beck\Documents\VuGen\Scripts\WebHttpHtml8\\default.cfg" [MsgId: MMSG-27141] Ending action vuser_init. Running Vuser... Starting iteration 1. Maximum number of concurrent connections per server: 6 [MsgId: MMSG-26989] Starting action Action. Action.c(5): Notify: Saving Parameter "host = 192.168.0.102". Action.c(6): Notify: Saving Parameter "port = 8081". Action.c(8): Notify: Saving Parameter "pwd = 123456". Action.c(12): web_reg_save_param started [MsgId: MMSG-26355] Action.c(12): Registering web_reg_save_param was successful [MsgId: MMSG-26390] Action.c(22): web_url("register") started [MsgId: MMSG-26355] Action.c(22): Notify: Parameter Substitution: parameter "host" = "192.168.0.102" Action.c(22): Notify: Parameter Substitution: parameter "port" = "8081" Action.c(22): Notify: Parameter Substitution: parameter "randomPhone" = "77753678" Action.c(22): Notify: Parameter Substitution: parameter "pwd" = "123456" Action.c(22): t=1414ms: 157-byte response headers for "http://192.168.0.102:8081/futureloan/mvc/api/member/register?mobilephone=13877753678&pwd=123456" (RelFrameId=1, Internal ID=1) Action.c(22): HTTP/1.1 200 OK\r\n Action.c(22): Server: Apache-Coyote/1.1\r\n Action.c(22): Content-Type: application/json;charset=UTF-8\r\n Action.c(22): Transfer-Encoding: chunked\r\n Action.c(22): Date: Sat, 09 Nov 2019 07:26:52 GMT\r\n Action.c(22): \r\n Action.c(22): t=1422ms: 4-byte chunked response overhead for "http://192.168.0.102:8081/futureloan/mvc/api/member/register?mobilephone=13877753678&pwd=123456" (RelFrameId=1, Internal ID=1) Action.c(22): 3c\r\n Action.c(22): t=1422ms: 7-byte chunked response overhead for "http://192.168.0.102:8081/futureloan/mvc/api/member/register?mobilephone=13877753678&pwd=123456" (RelFrameId=1, Internal ID=1) Action.c(22): \r\n Action.c(22): 0\r\n Action.c(22): \r\n Action.c(22): t=1426ms: 60-byte chunked response body for "http://192.168.0.102:8081/futureloan/mvc/api/member/register?mobilephone=13877753678&pwd=123456" (RelFrameId=1, Internal ID=1) Action.c(22): {"status":1,"code":"10001","data":null,"msg":"娉ㄥ唽鎴愬姛"} Action.c(22): Notify: Saving Parameter "register_response_1 = "status":1,"code":"10001","data":null,"msg":"娉ㄥ唽鎴愬姛"". Action.c(22): HTML parsing not performed for Content-Type "application/json" ("ParseHtmlContentType" Run-Time Setting is "TEXT"). URL="http://192.168.0.102:8081/futureloan/mvc/api/member/register?mobilephone=13877753678&pwd=123456" [MsgId: MMSG-26548] Action.c(22): Notify: Saving Parameter "register_response_count = 1". Action.c(22): web_url("register") was successful, 60 body bytes, 157 header bytes, 11 chunking overhead bytes [MsgId: MMSG-26385] Action.c(28): Notify: Parameter Substitution: parameter "register_response_count" = "1" Action.c(28): Notify: Parameter Substitution: parameter "register_response_1" = ""status":1,"code":"10001","data":null,"msg":"娉ㄥ唽鎴愬姛"" Action.c(28): Notify: Saving Parameter "register_result = "status":1,"code":"10001","data":null,"msg":"注册成功"\x00". Action.c(35): web_reg_save_param started [MsgId: MMSG-26355] Action.c(35): Registering web_reg_save_param was successful [MsgId: MMSG-26390] Action.c(44): web_reg_find started [MsgId: MMSG-26355] Action.c(44): Registering web_reg_find was successful [MsgId: MMSG-26390] Action.c(50): web_url("login") started [MsgId: MMSG-26355] Action.c(50): Notify: Parameter Substitution: parameter "host" = "192.168.0.102" Action.c(50): Notify: Parameter Substitution: parameter "port" = "8081" Action.c(50): Notify: Parameter Substitution: parameter "pwd" = "123456" Action.c(50): t=1575ms: 157-byte response headers for "http://192.168.0.102:8081/futureloan/mvc/api/member/login?mobilephone=13845968970&pwd=123456" (RelFrameId=1, Internal ID=2) Action.c(50): HTTP/1.1 200 OK\r\n Action.c(50): Server: Apache-Coyote/1.1\r\n Action.c(50): Content-Type: application/json;charset=UTF-8\r\n Action.c(50): Transfer-Encoding: chunked\r\n Action.c(50): Date: Sat, 09 Nov 2019 07:26:52 GMT\r\n Action.c(50): \r\n Action.c(50): t=1581ms: 4-byte chunked response overhead for "http://192.168.0.102:8081/futureloan/mvc/api/member/login?mobilephone=13845968970&pwd=123456" (RelFrameId=1, Internal ID=2) Action.c(50): 3c\r\n Action.c(50): t=1582ms: 7-byte chunked response overhead for "http://192.168.0.102:8081/futureloan/mvc/api/member/login?mobilephone=13845968970&pwd=123456" (RelFrameId=1, Internal ID=2) Action.c(50): \r\n Action.c(50): 0\r\n Action.c(50): \r\n Action.c(50): t=1582ms: 60-byte chunked response body for "http://192.168.0.102:8081/futureloan/mvc/api/member/login?mobilephone=13845968970&pwd=123456" (RelFrameId=1, Internal ID=2) Action.c(50): {"status":1,"code":"10001","data":null,"msg":"鐧诲綍鎴愬姛"} Action.c(50): Notify: Saving Parameter "login_response_1 = "status":1,"code":"10001","data":null,"msg":"鐧诲綍鎴愬姛"". Action.c(50): HTML parsing not performed for Content-Type "application/json" ("ParseHtmlContentType" Run-Time Setting is "TEXT"). URL="http://192.168.0.102:8081/futureloan/mvc/api/member/login?mobilephone=13845968970&pwd=123456" [MsgId: MMSG-26548] Action.c(50): Notify: Saving Parameter "login_response_count = 1". Action.c(50): Registered web_reg_find successful for "Text=10001" (count=1) [MsgId: MMSG-26364] Action.c(50): Notify: Saving Parameter "login_status = 1". Action.c(50): web_url("login") was successful, 60 body bytes, 157 header bytes, 11 chunking overhead bytes [MsgId: MMSG-26385] Action.c(56): Notify: Parameter Substitution: parameter "login_response_count" = "1" Action.c(56): Notify: Parameter Substitution: parameter "login_response_1" = ""status":1,"code":"10001","data":null,"msg":"鐧诲綍鎴愬姛"" Action.c(56): Notify: Saving Parameter "login_result = "status":1,"code":"10001","data":null,"msg":"登录成功"\x00". Action.c(60): Notify: Parameter Substitution: parameter "login_status" = "1" Action.c(61): ************登录成功***************** Ending action Action. Ending iteration 1. Ending Vuser... Starting action vuser_end. Ending action vuser_end. Vuser Terminated.

 

12|0十二. 注意点


1. 函数的书写格式 "url=http://{host}:{port}/futureloan/mvc/api/member/register?mobilephone={mobilephone}&pwd={pwd}", 而不是下面这样,还有要注意,如果这里是虚拟机,而服务部署在本机,host应该是本机的ip,而不是127.0.0.1

 

 

2. log设置,按F4,找到Log,勾选Extended log

 

 

3. 另外一个查函数的方法

 

 

 

 

 

 

 

 

 

 

 

 

 

 


__EOF__

本文作者cnhkzyy
本文链接https://www.cnblogs.com/my_captain/p/11817184.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   cnhkzyy  阅读(928)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示