lr——bbs

Action()
{

//将ip地址保存在参数中
lr_save_string("192.168.0.99","ip");

//登录用户名、密码
lr_save_string("user2","uname");
lr_save_string("111111","pwd");

//打开bbs首页
web_url("homePage",
"URL=http://{ip}/bbsutf8/",
"RecContentType=text/html",
"Mode=HTML",
LAST);

//在登录响应中检查是否出现error内容,使用Fail属性:找到error就直接失败
web_reg_find("Text=error",
"SaveCount=error_findcount",
// "Fail=Found",
LAST);

//在首页右上角,输入用户名、密码,进行登录
web_submit_data("loginSubmit",
"Action=http://{ip}/bbsutf8/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1",
"Method=POST",
"RecContentType=text/xml",
"Mode=HTML",
ITEMDATA,
"Name=fastloginfield", "Value=username", ENDITEM,
"Name=username", "Value={uname}", ENDITEM,
"Name=password", "Value={pwd}", ENDITEM,
"Name=quickforward", "Value=yes", ENDITEM,
"Name=handlekey", "Value=ls", ENDITEM,
LAST);


//登录完成后,重新加载页面
web_url("homePage2",
"URL=http://{ip}/bbsutf8/forum.php",
"RecContentType=text/html",
"Mode=HTML",
LAST);

//根据error出现次数判断登录是否成功。
if(atoi(lr_eval_string("{error_findcount}"))>0){
lr_error_message("Login failure :%s",lr_eval_string("{uname}"));
}
else{
lr_output_message("Login successfully :%s ",lr_eval_string("{uname}"));
}

//点击“默认版块”,打开默认版块页面
web_url("sectionPage",
"URL=http://{ip}/bbsutf8/forum.php?mod=forumdisplay&fid=2",
"RecContentType=text/html",
"Mode=HTML",
LAST);

/*
formhash关联步骤:
1.录制完成后,在第一次回放时,topicSubmit未能通过,在当前页面-发帖页面,查找要关联项:
在源码中查找hidden域、值为不规则的字段,确定formhash,而且此项在topicSubmit请求为数据部分,确定需要对formhash进行关联。
将关联语句,写在响应返回发帖页面的步骤之前,即点击发帖的postPage步骤前。
*/

// formhash关联
web_reg_save_param("formhash",
"LB=\"formhash\" value=\"",
"RB=\" />",
LAST);

//在默认版块,点击“发帖”,打开发帖页面
web_url("postPage",
"URL=http://{ip}/bbsutf8/forum.php?mod=post&action=newthread&fid=2&referer=http%3A//{ip}/bbsutf8/forum.php%3Fmod%3Dforumdisplay%26fid%3D2",
"RecContentType=text/html",
"Mode=HTML",
LAST);
/*
tid关联步骤
formhash关联后,再次运行,通过返回页面查看,发现并未在当前主题下面进行回复。而是回复在录制时发布的主题。
查看replysubmit请求,发现其中Action属性中 参数tid为主题的id。需对tid进行关联。
在已发布的主题页面,查找tid值的左右边界,取htmlbody中较显著的地方--主题标题。(从firebug看是整理过的,要看源码)
将关联语句写在响应返回主题页面的步骤之前,即发布主题的topicSubmit步骤前。

*/
//tid关联
web_reg_save_param("tid",
"LB=viewthread&tid=",
"RB=\" id=\"thread_subject\">",
LAST);
//检查发贴主题
web_reg_find("Text=subject000",
"SaveCount=subject_findcount",
LAST);

//发帖事务开始
lr_start_transaction("topicSubmit");

//在发帖页,输入帖子标题和内容,发布帖子
web_submit_data("topicSubmit",
"Action=http://{ip}/bbsutf8/forum.php?mod=post&action=newthread&fid=2&extra=&topicsubmit=yes",
"Method=POST",
"RecContentType=text/html",
"Mode=HTML",
ITEMDATA,
"Name=formhash", "Value={formhash}", ENDITEM,
"Name=posttime", "Value=1415301992", ENDITEM,
"Name=wysiwyg", "Value=1", ENDITEM,
"Name=subject", "Value=subject000", ENDITEM,
"Name=message", "Value=message123~~~message123~~~", ENDITEM,
"Name=replycredit_extcredits", "Value=0", ENDITEM,
"Name=replycredit_times", "Value=1", ENDITEM,
"Name=replycredit_membertimes", "Value=1", ENDITEM,
"Name=replycredit_random", "Value=100", ENDITEM,
"Name=save", "Value=", ENDITEM,
"Name=usesig", "Value=1", ENDITEM,
"Name=allownoticeauthor", "Value=1", ENDITEM,
LAST);

//根据subject_findcount值,自定义topicSubmit事务

if(atoi(lr_eval_string("{subject_findcount}"))==0){
lr_end_transaction("topicSubmit",LR_FAIL);
lr_error_message("topicSubmit transaction failure");
}else{
lr_end_transaction("topicSubmit",LR_PASS);
lr_output_message("subject_findcount:%d",atoi(lr_eval_string("{subject_findcount}")));
}

/*
关联tid后,运行到最后一步,发现请求路径不正确,观看getNewpost的URL参数中viewpid也需关联。
因pid为帖子id,为在回复完成后响应到的。在查看回复的响应后,发现响应内容中有pid的值。
所以在回复步骤replysubmit前,写关联语句。
*/

//pid关联
web_reg_save_param("pid",
"LB=&pid=",
"RB=&page=",
LAST);

//回帖事务
lr_start_transaction("replysubmit");

//帖子发布完成后,在帖子页面,下方输入回复内容,回复帖子
web_submit_data("replysubmit",
"Action=http://{ip}/bbsutf8/forum.php?mod=post&action=reply&fid=2&tid={tid}&extra=&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1",
"Method=POST",
"RecContentType=text/xml",
"Mode=HTML",
ITEMDATA,
"Name=message", "Value=reply000~~~reply000~~~", ENDITEM,
"Name=posttime", "Value=1415302041", ENDITEM,
"Name=formhash", "Value={formhash}", ENDITEM,
"Name=subject", "Value=", ENDITEM,
LAST);

//回帖事务结束
lr_end_transaction("replysubmit",LR_AUTO);

//检查回帖内容
web_reg_find("Text=reply000~~~reply000~~~",
LAST);

//回复完成后,页面加载最新发布的帖子
web_url("getNewpost",
"URL=http://{ip}/bbsutf8/forum.php?mod=viewthread&tid={tid}&viewpid={pid}&from=&inajax=1&ajaxtarget=post_new",
"RecContentType=text/xml",
"Mode=HTML",
LAST);

//加载完整主题页面
web_url("topicPage",
"URL=http://{ip}/bbsutf8/forum.php?mod=viewthread&tid={tid}&extra=page%3D1",
LAST);

return 0;
}

 

posted @ 2015-03-02 16:38  hotarubi  阅读(427)  评论(0编辑  收藏  举报