loadrunner脚本函数讲解

时间:2021-08-07 00:25:21

一、 get请求和post请求
区别:web_link(get)、web_submit_form(post)依赖上下文,web_url、web_submit_data不依赖上下文,建议使用web_url(get)、web_submit_data(post)请求。

web_url("web_url",
"URL=https://mp.csdn.net/",
"TargetFrame=",
"Resource=0",
"Referer=",
EXTRARES,
"URL=a", "Referer=a", ENDITEM,
LAST);

web_submit_data可以有post和get请求

web_submit_data("web_submit_data",
"Action=https://aaa.hs.net:8442/",
"Method=POST",
"TargetFrame=",
"Referer=",
ITEMDATA,
"Name=a", "Value=a", ENDITEM,
"Name=b", "Value=b", ENDITEM,
LAST);

web_custom_request只有get请求

web_custom_request("orderAdd",
"URL=https://TTT.hs.net:8443/",
"Method=GET",
"Mode=HTTP",
"Body=ajaxPostData={\"name\":\"value\",\"name1\":\"value1\"}",
LAST);

一般loadrunner安装完默认是的web_link、web_submit_form,需要修改如下选项:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190302134711286.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzQxOTE3MzA2,size_16,color_FFFFFF,t_70)

二、 关联函数
1)web_reg_save_param:必须放在请求前面,`"`要用`\"`转义

web_reg_save_param("text",
"LB=a\"”",
"RB=/b",
LAST);

web_url("web_url",
"URL=https://cc.com",
"TargetFrame=",
"Resource=0",
"Referer=",
EXTRARES,
"URL=a", "Referer=a", ENDITEM,
LAST);

lr_output_message(lr_eval_string("{text}"));

2)关联函数通配符以及关联数组应用
`#`表示`0-9数字`
`Ord`表示要哪个值
`IgnoreRedirections`忽略重定向
`Ord=All`表示获取到所有值存到test1数组中

web_reg_save_param("test1",
"LB/DIG=a\"##",
"RB=v",
"Ord=All",
"SaveOffset=5",
"SaveLen=8",
"IgnoreRedirections=Yes",
LAST);

lr_save_string(lr_paramarr_random("test1"),"param")

数组相关函数:
lr_paramarr_idx("string",1):数组的第一个索引值
lr_paramarr_len("string"):数组的长度
lr_save_string(lr_paramarr_random("string"),"string1"):随机输出数组值存储到string1

![在这里插入图片描述](https://img-blog.csdnimg.cn/20190302163907566.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzQxOTE3MzA2,size_16,color_FFFFFF,t_70)

三、 事务
1)事务:
统计事务的成功率
统计每一个请求或者一批请求的响应时间

不勾选下图两个
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190304104342576.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzQxOTE3MzA2,size_16,color_FFFFFF,t_70)

lr_start_transaction("test")
...
lr_end_transaction("test", LR_AUTO/LR_PASS/LR_FAIL);

LR_AUTO是根据响应的状态码进行判断

四、检查点函数
aito:字符串转换成整数

web_reg_find("SaveCount=testcount",
"Text=test",
LAST);
if(aito(le_eval_string("{testcount}"))==1)
{

}
else{

}

五、思考时间

lr_think_time(20)

勾选“Replay think time”则表示模拟用户思考时间,一般用户的思考时间不一样,使用随机数,不能设置的太长,如图所示
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190304163043740.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzQxOTE3MzA2,size_16,color_FFFFFF,t_70)

六、集合点
适用于并发测试,有两种情况:
1、所有用户都在请求服务器
2、所有用户都在同一时间提交同一个请求

压力测试(不需要思考时间)
负载测试:最大用户数(某一个指标到达极限)
并发测试(相对严格的并发)
稳定性测试:长时间的,最佳用户(系统处于最佳状态)
容量测试:数据库中有很大的数据的前提下进行压测

lr_rendezvous("test");
集合点要放置在事务前面

七、web_set_option()
设置Web选项。(对web录制或者运行脚本设置选项)
web_set_option(“DecodeContent”,“No”,LAST):禁用解码
web_set_option(“DecodeContent”,“Yes”,LAST):启用解码
web_set_option(“MaxRedirectionDepth”,“0”,LAST):禁用重定向
参考:https://blog.csdn.net/testingstar/article/details/78106131