TA的每日心情 | 奋斗 2018-9-19 14:34 |
---|
签到天数: 5 天 连续签到: 1 天 [LV.2]测试排长
|
web_submit_data函数,成功返回0,失败返回1
1.录制一个示例脚本(登录),脚本内容如下:
Action()
{
web_url("booking",
"URL=http://localhost/test",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);
/*进行登录操作*/
lr_think_time(8);
web_reg_find("Text=chenyinhua", //检查点
"SaveCount=a",
LAST);
web_submit_data("loginAction!loginQuick.action",
"Action=http://localhost/test/loginAction!loginQuick.action",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost/test/",
"Snapshot=t8.inf",
"Mode=HTML",
ITEMDATA,
"Name=orderwebUser.userName", "Value=Y2hlbnlpbmh1YQ==/", ENDITEM,
"Name=userPassword", "Value=MTIzNDU2", ENDITEM,
"Name=certCode", "Value=1111", ENDITEM,
LAST);
return 0;
}
2.在脚本最开始,定义一个变量,用于判断登录是否成功
int status;
3.将web_submit_data的返回值赋值给status,如下:
status=web_submit_data("loginAction!loginQuick.action",
"Action=http://localhost/test/loginAction!loginQuick.action",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost/test/",
"Snapshot=t8.inf",
"Mode=HTML",
ITEMDATA,
"Name=orderwebUser.userName", "Value=Y2hlbnlpbmh1YQ==/", ENDITEM,
"Name=userPassword", "Value=MTIzNDU2", ENDITEM,
"Name=certCode", "Value=1111", ENDITEM,
LAST);
4.写入一个判断,输出status的值
if(status==1) //一旦登录失败,脚本给出提示报错信息
{
lr_error_message("错误信息:%s","不能正常登录");
return -1;
}else if(status==0){
lr_output_message("登录成功。status=%d",status);
return 0;
}else{
lr_output_message("异常");
}
这里也可以用status的值,来判断登录事务是成功还是失败。
5.所以,整合后的脚本如下:
Action()
{
int status; //定义变量,用于判断登录是否成功
web_url("booking",
"URL=http://localhost/test",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);
/*进行登录操作*/
lr_think_time(8);
web_reg_find("Text=chenyinhua",
"SaveCount=a",
LAST);
status=web_submit_data("loginAction!loginQuick.action",
"Action=http://localhost/test/loginAction!loginQuick.action",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost/test/",
"Snapshot=t8.inf",
"Mode=HTML",
ITEMDATA,
"Name=orderwebUser.userName", "Value=Y2hlbnlpbmh1YQ==/", ENDITEM,
"Name=userPassword", "Value=MTIzNDU2", ENDITEM,
"Name=certCode", "Value=1111", ENDITEM,
LAST);
if(status==1) //一旦登录失败,脚本给出提示报错信息
{
lr_error_message("错误信息:%s","不能正常登录");
return -1;
}else if(status==0){
lr_output_message("登录成功。status=%d",status);
return 0;
}else{
lr_output_message("异常");
} |
|