一、参数
1. 在LR函数中可以直接使用参数。常见的有关联参数和参数化参数。
2. 保存为参数的函数常用的有
3. 参数数组函数
二、变量
1. 变量是标准C语言里的,如果要在脚本中使用需要先转化为Lr参数。
Action()
{
char achievepart1[1024]; //声明数组
char achievepart2[1024];
char achievementIdcopies[1024];
web_url("tologin.html",
"URL=http://10.0.47.91:8088/kmsystem/login/tologin.html?v=1497492412937",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://10.0.47.91:8088/kmsystem/",
"Snapshot=t2.inf",
"Mode=HTML",
EXTRARES,
"URL=../skins/blue/img/bg.jpg", "Referer=http://10.0.47.91:8088/kmsystem/login/tologin.html?v=1497492412937", ENDITEM,
"URL=/favicon.ico", ENDITEM,
"URL=http://www.bing.com/favicon.ico", ENDITEM,
LAST);
web_reg_save_param("achievementId",
"LB=<li class=\"Listli\"><a href=\"javascript:kycgKmDetil(\'",
"RB=');\" title=",
"Ord=4",
LAST);
// lr_start_transaction("login");
web_submit_data("login.html",
"Action=http://10.0.47.91:8088/kmsystem/login/login.html",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://10.0.47.91:8088/kmsystem/login/tologin.html?v=1497492412937",
"Snapshot=t3.inf",
"Mode=HTML",
ITEMDATA,
"Name=from", "Value=", ENDITEM,
"Name=docId", "Value=", ENDITEM,
"Name=projectId", "Value=", ENDITEM,
"Name=domainaccount", "Value=", ENDITEM,
"Name=username", "Value={username}", ENDITEM,
"Name=password", "Value=123", ENDITEM,
EXTRARES,
"URL=../static/public/skins/default.css?4.1.7", "Referer=http://10.0.47.91:8088/kmsystem/homePage/toHomePage.html", ENDITEM,
"URL=../static/modules/js/homeMain/homeMainFront/homeMain.js", "Referer=http://10.0.47.91:8088/kmsystem/homePage/toHomePage.html", ENDITEM,
"URL=../static/framework/img/icons/loading.gif", "Referer=http://10.0.47.91:8088/kmsystem/homePage/toHomePage.html", ENDITEM,
LAST);
strcpy(achievementIdcopies,lr_eval_string("{achievementId}")); //参数复制到c变量
//593d3a9d3e2b1b17969efd45','593bae4258e97f167bf088be
strncpy(achievepart1,achievementIdcopies,24); //被复制到的变量,参数1,|将第二个参数字符截取前24位保存到第一个参数中,参数2|截取位数,参数3
strcpy(achievepart2,achievementIdcopies+27); //被复制到的变量,参数1 |将第二个参数字符从第27位截取,保存到第一个参数中
lr_message("achievepart1= %s",achievepart1);
lr_message("achievepart2===== %s",achievepart2);
Action.c(41): web_submit_data("login.html") was successful, 455417 body bytes, 9482 header bytes, 36 chunking overhead bytes [MsgId: MMSG-26385]
achievepart1= 593d3a9d3e2b1b17969efd45
achievepart2===== 593bae4258e97f167bf088be1.
2. 局部变量在本脚本(当前action)声明中使用。全局变量,则应该在globals.h中定义变量。
参数和变量的使用:
1. 字符型变量和参数的转换
lr_save_string("teststring","param"); 将字符串teststring保存到参数param中
lr_eval_string("{param}"); 取出参数param中的值
2. 整型变量和参数的转换
int x;
x = 10;
lr_save_int(x,"param"); 将整形变量保存到参数param中
x = atoi(lr_eval_string("{param}")); 取出参数param中的数值保存到变量x
Action()
{
char achievepart1[1024]; //声明数组
char achievepart2[1024];
char achievementIdcopies[1024];
char randOrd[10]; //随机Ord做为随机选择文件ID
int randRow = rand() % 7; //随机操作列表
if (randRow==0) {
randRow+=1;
}
itoa(randRow, randOrd , 10);//转换为字符串
lr_save_string(randOrd,"randOrd"); //转换为参数
web_url("kmsystem",
"URL=http://10.0.47.91:8088/kmsystem/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
web_url("tologin.html",
"URL=http://10.0.47.91:8088/kmsystem/login/tologin.html?v=1497492412937",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://10.0.47.91:8088/kmsystem/",
"Snapshot=t2.inf",
"Mode=HTML",
EXTRARES,
"URL=../skins/blue/img/bg.jpg", "Referer=http://10.0.47.91:8088/kmsystem/login/tologin.html?v=1497492412937", ENDITEM,
"URL=/favicon.ico", ENDITEM,
"URL=http://www.bing.com/favicon.ico", ENDITEM,
LAST);
web_reg_save_param("achievementId",
"LB=<li class=\"Listli\"><a href=\"javascript:kycgKmDetil(\'",
"RB=');\" title=",
"Ord={randOrd}",
LAST);
lr_start_transaction("login");
web_submit_data("login.html",
"Action=http://10.0.47.91:8088/kmsystem/login/login.html",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://10.0.47.91:8088/kmsystem/login/tologin.html?v=1497492412937",
"Snapshot=t3.inf",
"Mode=HTML",
ITEMDATA,
"Name=from", "Value=", ENDITEM,
"Name=docId", "Value=", ENDITEM,
"Name=projectId", "Value=", ENDITEM,
"Name=domainaccount", "Value=", ENDITEM,
"Name=username", "Value={username}", ENDITEM,
"Name=password", "Value=123", ENDITEM,
EXTRARES,
"URL=../static/public/skins/default.css?4.1.7", "Referer=http://10.0.47.91:8088/kmsystem/homePage/toHomePage.html", ENDITEM,
"URL=../static/modules/js/homeMain/homeMainFront/homeMain.js", "Referer=http://10.0.47.91:8088/kmsystem/homePage/toHomePage.html", ENDITEM,
"URL=../static/framework/img/icons/loading.gif", "Referer=http://10.0.47.91:8088/kmsystem/homePage/toHomePage.html", ENDITEM,
LAST);
strcpy(achievementIdcopies,lr_eval_string("{achievementId}")); //第一步:关联参数复制到c变量
//'593d3a9d3e2b1b17969ef,d45','593bae4258e97f16,7bf088be'
strncpy(achievepart1,achievementIdcopies,24); //第二步:将一个长参数分为2个参数。________被复制到的变量,参数1,|将第二个参数字符截取前24位保存到第一个参数中,参数2|截取位数,参数3
strcpy(achievepart2,achievementIdcopies+27); //被复制到的变量,参数1 |将第二个参数字符从第27位截取,保存到第一个参数中
lr_message("achievepart1= %s",achievepart1);
lr_message("achievepart2===== %s",achievepart2);
lr_save_string(achievepart1,"achievepart1");//第三步:再将分好的变量转为参数。
lr_save_string(achievepart2,"achievepart2");
lr_message("part1= %s",lr_eval_string("{achievepart1}"));
web_custom_request("getSearchList.html",
"URL=http://10.0.47.91:8088/kmsystem/homePage/getSearchList.html",
"Method=POST",
"TargetFrame=",
"Resource=0",
"RecContentType=text/plain",
"Referer=http://10.0.47.91:8088/kmsystem/homePage/toHomePage.html",
"Snapshot=t4.inf",
"Mode=HTML",
"EncType=",
LAST);
//共有205页,遍历每一页面
for(i=1;i<=205;i++){
//如果在该页找到检查点,则退出循环
if(atoi(lr_eval_string("{modify_Count}"))>0){
lr_output_message("在第%d页面已找到检查点",temp);//1,2,3
return -1;
}else{
//在每页做文本检查点
web_reg_find("Text=101036",
"SaveCount=modify_Count",
LAST);
temp = 1+i;
//将int类型转换为string类型,以10进制保存
itoa(temp,str,10);
lr_save_string(str,"next");
//点击下一页
web_submit_data("admin_list",
...
}
}
return 0;
}