需要注意两点:
1、声明的变量放在action前
2、int和string之间的转换使用sprintf函数
#include "web_api.h"
char para1[50];
int i;
Action()
{
web_url("login.ftl",
"URL=http://192.168.0.5:7001/bank/login.ftl",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_think_time(11);
web_submit_form("login.do",
"Snapshot=t2.inf",
ITEMDATA,
"Name=userName", "Value=admin", ENDITEM,
"Name=password", "Value=admin", ENDITEM,
"Name=code", "Value=dddd", ENDITEM,
"Name=imageField.x", "Value=40", ENDITEM,
"Name=imageField.y", "Value=8", ENDITEM,
EXTRARES,
"URL=include/css.css", "Referer=http://192.168.0.5:7001/bank/main.ftl", ENDITEM,
"URL=images/dbrw_bg.gif", "Referer=http://192.168.0.5:7001/bank/top.do?cmd=list", ENDITEM,
"URL=images/folderOpen.gif", "Referer=http://192.168.0.5:7001/bank/manage.do?method=showMenu", ENDITEM,
"URL=images/leftmenu_bg2.gif", "Referer=http://192.168.0.5:7001/bank/manage.do?method=showMenu", ENDITEM,
"URL=images/folderClose.gif", "Referer=http://192.168.0.5:7001/bank/manage.do?method=showMenu", ENDITEM,
"URL=images/plus.gif", "Referer=http://192.168.0.5:7001/bank/manage.do?method=showMenu", ENDITEM,
"URL=images/minus.gif", "Referer=http://192.168.0.5:7001/bank/manage.do?method=showMenu", ENDITEM,
"URL=images/file.gif", "Referer=http://192.168.0.5:7001/bank/manage.do?method=showMenu", ENDITEM,
"URL=images/blank.gif", "Referer=http://192.168.0.5:7001/bank/manage.do?method=showMenu", ENDITEM,
LAST);
lr_think_time(4);
web_url("newuser.do",
"URL=http://192.168.0.5:7001/bank/newuser.do?cmd=list",
"Resource=0",
"RecContentType=text/html",
"Referer=http://192.168.0.5:7001/bank/manage/body.html",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);
lr_think_time(3);
web_submit_data("newuser.do_2",
"Action=http://192.168.0.5:7001/bank/newuser.do",
"Method=POST",
"RecContentType=text/html",
"Referer=http://192.168.0.5:7001/bank/newuser.do?cmd=list",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=opNmae", "Value=user_add", ENDITEM,
"Name=cmd", "Value=add", ENDITEM,
"Name=cid", "Value=", ENDITEM,
"Name=mulitCid", "Value=", ENDITEM,
"Name=page", "Value=1", ENDITEM,
"Name=orderField", "Value=", ENDITEM,
"Name=orderType", "Value=", ENDITEM,
"Name=queryIsInsideUser", "Value=1", ENDITEM,
"Name=queryId", "Value=", ENDITEM,
"Name=queryName", "Value=", ENDITEM,
"Name=queryDeptName", "Value=", ENDITEM,
"Name=queryDept", "Value=", ENDITEM,
"Name=queryFlag", "Value=", ENDITEM,
LAST);
lr_think_time(13);
web_url("choice.do",
"URL=http://192.168.0.5:7001/bank/choice.do?cmd=chooseDepartment",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t5.inf",
"Mode=HTML",
LAST);
lr_think_time(1);
web_url("choice.do_2",
"URL=http://192.168.0.5:7001/bank/choice.do?cmd=chooseRole",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t6.inf",
"Mode=HTML",
LAST);
lr_think_time(2);
web_url("choice.do_3",
"URL=http://192.168.0.5:7001/bank/choice.do?cmd=chooseTreeRole",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t7.inf",
"Mode=HTML",
LAST);
lr_think_time(5);
for(i=1;i<=20;i++)//循环次数
{
sprintf(para1,"Value=bbbbb%d",i);//类型转换
web_submit_data("newuseredit.do",
"Action=http://192.168.0.5:7001/bank/newuseredit.do",
"Method=POST",
"RecContentType=text/html",
"Referer=http://192.168.0.5:7001/bank/newuser.do",
"Snapshot=t8.inf",
"Mode=HTML",
ITEMDATA,
"Name=opNmae", "Value=user_add", ENDITEM,
"Name=cmd", "Value=insert", ENDITEM,
"Name=cid", "Value=", ENDITEM,
"Name=mulitCid", "Value=", ENDITEM,
"Name=org.apache.struts.taglib.html.TOKEN", "Value=bc7de064fe60c22a97dd17c6f9324cdf", ENDITEM,
"Name=roleCodeString", "Value=1,65,", ENDITEM,
"Name=roleNameString", "Value=", ENDITEM,
"Name=treeRoleCodeString", "Value=25,69,", ENDITEM,
"Name=treeRoleNameString", "Value=", ENDITEM,
"Name=orgName", "Value=", ENDITEM,
"Name=orgCode", "Value=", ENDITEM,
"Name=createoper", "Value=", ENDITEM,
"Name=recordstarttime", "Value=", ENDITEM,
"Name=recordstoptime", "Value=", ENDITEM,
"Name=isinsideuser", "Value=", ENDITEM,
"Name=logontimes", "Value=", ENDITEM,
"Name=lastlogontime", "Value=", ENDITEM,
"Name=userid", para1, ENDITEM,
"Name=username", para1, ENDITEM,
"Name=userpwd", "Value=aaaaaa", ENDITEM,
"Name=email", "Value=aaaaaa@sdfas.dsfsd", ENDITEM,
"Name=telephone", "Value=", ENDITEM,
"Name=zip", "Value=", ENDITEM,
"Name=address", "Value=", ENDITEM,
"Name=userdesc", "Value=", ENDITEM,
"Name=departmentName", "Value=广州分行", ENDITEM,
"Name=departmentCode", "Value=27", ENDITEM,
"Name=recordstopflag", "Value=0", ENDITEM,
LAST);
lr_think_time(60);
lr_message("%s",para1);//打印
}
web_url("manage.do",
"URL=http://192.168.0.5:7001/bank/manage.do?method=logout",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t9.inf",
"Mode=HTML",
LAST);
return 0;
}