loadrunner基本操作
1.输出:
lr_output_message(" ")
2.格式化输入
lr_output_message("姓名:%s 性别:%s 年龄:%d","lizhao","男",12)
3.注释
注释单行
//lr_output_message(" ")
注释多行
/*
lr_output_message(" ")
lr_output_message(" ")
*/
4.定义变量与格式化输出
char *name = "朝阳"
注意:所有的变量定义必须放在脚本的最上方
lr_output_message("用户名:%s",name)
5.Runtime Settings
位置:Relay->Runtime Settings
1> Run Logic:定义action运行次数(顺序等概率,随机自定义概率)
2> Pacing:立即执行下一次、本次迭代结束与下一次迭代开始之间的等待时间、本次迭代开始到下一次迭代开始的等待时间
3> Log:日志,通常不建议开启。启动时,开启一直写log模式(Always-> Extended->Parameter),只打印参数化log
4>Think Time:思考时间。Relay think time:As recorded(录制时的思考时间)、random(百分比思考时间)
脚本中:lr_think_time(3);
6.取参数值
简单示例:
char *name="朝阳";
lr_output_message(lr_eval_string(name));
7.取参数值
将lr_output_message(“中文”);中的中文选中右键选择Replace with a Parameter
8.时间戳函数
web_save_timestamp_param("date",LAST);
lr_output_message("时间戳:%s",lr_eval_string("{date}"))
9.获取web上的字符串长度
1 Action() 2 { 3 4 web_reg_save_param("home", 5 "LB=account", 6 "RB=to the left", 7 "NotFound=ERROR", 8 "Search=NoResource", 9 LAST 10 ); 11 12 web_url("index.htm", 13 "URL=http://127.0.0.1:1080/WebTours/index.htm", 14 "Resource=0", 15 "RecContentType=text/html", 16 "Referer=", 17 "Snapshot=t1.inf", 18 "Mode=HTML", 19 LAST); 20 lr_output_message(lr_eval_string("{home}")); 21 lr_output_message("截取字符长度:%d",strlen(lr_eval_string("{home}"))); 22 23 return 0; 24 }
10. 缓冲字符串内容截取
函数:lr_save_searched_string(const char *buffer,long buf_size,unsigned int occurrence,const char *search_string,int offset,unsigned int string_len,const char *parm_name)
参数解释:
buffer:STRING或CARRAY缓冲区,其中的部分内容要保存
buf_size:缓冲区大小
occurrence:search_string的出现次数(从0开始计数)
search_string:要在缓冲区中搜索的字符串
offset:在搜索字符串发生结束后要跳过的字符数
string_len:要保存的字符数
parm_name:截取结果保存到参数名
1 Action() 2 { 3 // 取ssss 4 char *buff="abc 123 abd abc dssss abc"; 5 lr_save_searched_string( 6 buff, //缓存字符 7 strlen(buff), //缓存字符长度 8 1, //abc出现的位置 9 "abc", //搜索字符串 10 2, //偏移量 11 4, //保存字符长度 12 "buff_abc" //以该变量输出 13 ); 14 15 lr_output_message("查看字符串:%s",lr_eval_string("{buff_abc}")); 16 return 0; 17 }
11.比较字符串大小strcmp
1 Action() 2 { 3 int result; 4 char *one = "hello"; 5 char *two = "Hello"; 6 7 /*比较字符串大小 8 1.result为0 str1==res2; 9 2.result为负数 str1<str2; 10 3.result为正数 str1>str2; 11 */ 12 result = strcmp(one,two); 13 if (result==0){ 14 lr_output_message("one等于two"); 15 }else if (result>0){ 16 lr_output_message("one大于two"); 17 }else{ 18 lr_output_message("one小于two"); 19 } 20 21 return 0; 22 }
以下为loadrunner11
12. 检查点 注册函数
右键点击脚本空白处,Insert->New Step->web_reg_find。
输入参数:
search for specific Text:需要查找的文本
Search in:All、Body、Headers 指定在哪里查找
Save count:输入变量,将找到的次数用该变量返回
Fail if:Found、NotFound,找到时返回结果或者没有找到时返回结果
注意:
1、函数必须放在请求开始位置之前;
2、使用结果时,必须在请求函数结束为止之后
13.事务和集合点
定义:事务是指用户在应用上完成一种或多种业务的一个集合,通过事务函数可以标记完成该业务所需要的操作内容,另一个层面事务可以帮我们统计完成业务所需要的时间。
事务响应时间:用户请求开始时间和服务器返回内容到客户端的时间差。
问题排查步骤:
1、优先查本机
2、查网络
3、查连接数 ps -ef
4、服务器资源
5、数据库资源
6、查数据库
7、程序
帮助文档:help->Function Reference