lr采用c的语法,有区别
• //定义c 变量 :c变量需全部放置前面
• char *p “usrname”;
• char var[10] “123”;
• int count 10
• lr_log_message("p is %s",p);
• lr_log_message("count is %d", count);
转换函数
• 参数转变量
• lr_save_string(p,"username") //Saves a null terminated string as a parameter.将c字符串赋值变量p保存为lr的变量usename
• lr_eval_string("{username}") //Returns the string argument after evaluating embedded parameters.将lr参数username值返回成c可用的字符串参数
.
字符串常用函数
char *p; 单个字符串
char var[10]; 长度问题
字符串操作: copy cat strcmp strlen
strcpy(var,lr_eval_string("{param}")); 赋值
strcat(var,lr_eval_string("{param}")); 拼接
• strcmp (lr_eval_string("{param}"),"str"):将两
个字符串类型的变量进行比较,如果相等,返回0,
否则,返回1或-1
memset(test,0,sizeof(test)); //字符串清空函数
--------------------------------------
• if(strcmp(lr_eval_string("{mysessiontest}"),“”)==0)
{
lr_log_message("yes");
• }else{
• lr_log_message("no");
• }
---------------------------
int size;
size = lr_paramarr_len("param_arry"):获取参数数组param_arry的长度,并保存到C语言的变量size里
字符串清空
memset(str,0,sizeof(str));
==============字符串例子==============
Action()
{
char test[20];
char *p;
strcat(test,"admin");
strcat(test,"pwd");
strcat(test,"0710");
lr_log_message("test is %s",test);
web_reg_save_param("mysessiontest","LB=userSession value=","RB=>",LAST);
web_url("WebTours", "URL=http://127.0.0.1:1080/WebTours/", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST);
lr_log_message("mysession is %s",lr_eval_string("{mysessiontest}"));
lr_log_message("test is %s",test); lr_log_message("test sizeis %d",strlen(test));
lr_log_message("mysession sizeis %d",
strlen(lr_eval_string("{mysessiontest}")));
if(strcmp(lr_eval_string("{mysessiontest}"),test)==0){
lr_log_message("yes");
}else{
lr_log_message("no");
}
web_reg_find("Text=Welcome,admin1",
LAST);
lr_think_time(26);
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={mysessiontest}", ENDITEM,
"Name=username", "Value=admin1", ENDITEM,
"Name=password", "Value=admin1", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=55", ENDITEM,
"Name=login.y", "Value=4", ENDITEM,
LAST);
return 0;
}
整数比较函数
• atoi(lr_eval_string("{param}")):将LR参数{param}转换为 数字
• //验证是否找到了页面上的要检查的字符串
• if (atoi(lr_eval_string("{para_count}"))>0) {
• lr_output_message("login success!");
• }
• else{
• lr_output_message("login error");
• }
数组应用
web_reg_save_param("JSESSIONID2", //JSESSIONID2存储数据若有多个则以数组形式保存
"LB/IC=jsessionid=",
"RB/IC=\"",
"Ord=ALL",
"Search=body",
"NotFound=WARNING",
LAST);
lr_paramarr_random("param_arry"):从参数数组param_arry中随机取一个值
int size;
size = lr_paramarr_len("param_arry"):获取参数数组param_arry的长度,并保存到C语言的变量size里
char *v;
value = lr_paramarr_idx("param_arry",1):获取参数数组param_arry中第1个值,并保存到C语言的变量value里
for 循环数组使用,
for(i=1;i<size;i++){
lr_log_message("param_arry is ",lr_paramarr_idx("param_arry",i))
}
==============例子=============
web_reg_save_param("mysession",
"LB=userSession value=",
"RB=>",
LAST);
lr_log_message("mysession is %s",lr_eval_string("{mysession}"));
lr_eval_string("{mysession}") 读取lr函数的参数