关联是将服务器返回的数据通过一定的规则过滤出来,并将其保存为参数,以供后续的代码中使用
当服务器返回的数据是动态化的,且后续脚本中需要使用这个动态变化的数据
LR提供了关联函数web_reg_save_param,通过设置左右边界和取值范围来获取服务器返回的数据(关联函数必须放在对应请求之前,先注册,后使用)
1、首先,在要测试页面点击鼠标右键,点击查看源文件
2、在html源文件中找到各板块链接
通过观察可以得出规律,每个板块的url前半部分一致。
因此得出~
左边界为“forunAction_show.action?id=”
右边界为“"”
3、点击Insert–>New Step,输入关联函数名称web_reg_save_param,点击OK添加函数~
(此处要注意,所有引号都要用反斜杠转义哟~)
添加好之后,脚本中会自动生成如下代码段~
打开扩展日志打印
打印结果如下~
最后把脚本中所有取板块id的地方修改为fids即可
脚本内容如下:
Action()
{
web_set_max_html_param_len("1024");
web_reg_save_param("JSESSIONID2",
"LB/IC=jsessionid=",
"RB/IC=\"",
"Ord=1",
"Search=body",
"RelFrameId=1",
LAST);
web_url("userAction_loginUI.action",
"URL=http://localhost:8080/TestOA/userAction_loginUI.action",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=style/blue/images/login_bg.gif", ENDITEM,
"Url=style/blue/images/login.gif", ENDITEM,
LAST);
web_submit_data("userAction_login.action;jsessionid=27C9A6FAA6FA9D92E13DBD466B03FB1D",
"Action=http://localhost:8080/TestOA/userAction_login.action;jsessionid={JSESSIONID2}",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/userAction_loginUI.action",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=loginName", "Value=admin", ENDITEM,
"Name=password", "Value=1234", ENDITEM,
"Name=x", "Value=52", ENDITEM,
"Name=y", "Value=22", ENDITEM,
EXTRARES,
"Url=style/blue/images/head2_bg.gif", "Referer=http://localhost:8080/TestOA/homeAction_top.action", ENDITEM,
"Url=style/blue/images/menu_btn_bg.gif", "Referer=http://localhost:8080/TestOA/homeAction_left.action", ENDITEM,
"Url=style/blue/images/top_bg.gif", "Referer=http://localhost:8080/TestOA/homeAction_top.action", ENDITEM,
LAST);
web_reg_save_param("fids",
"LB=forumAction_show.action?id=",
"RB=\"",
"Ord=all",
LAST);
web_url("论坛",
"URL=http://localhost:8080/TestOA/forumAction_list.action",
"TargetFrame=right",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/homeAction_left.action",
"Snapshot=t3.inf",
"Mode=HTML",
EXTRARES,
"Url=style/blue/images/title_bg.gif", ENDITEM,
"Url=style/blue/images/inputPageHeadBg.gif", ENDITEM,
"Url=style/blue/images/title_bg_head.gif", ENDITEM,
"Url=style/blue/images/title_bg_end.gif", ENDITEM,
LAST);
web_url("技术交流",
"URL=http://localhost:8080/TestOA/forumAction_show.action?id={fids_2}",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/forumAction_list.action",
"Snapshot=t4.inf",
"Mode=HTML",
EXTRARES,
"Url=style/blue/images/pageSelector_bg.gif", "Referer=http://localhost:8080/TestOA/forumAction_show.action?id={fid}", ENDITEM,
LAST);
web_url("publishNewTopic.png",
"URL=http://localhost:8080/TestOA/topicAction_addUI.action?forumId={fids_2}",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/forumAction_show.action?id={fids_2}",
"Snapshot=t5.inf",
"Mode=HTML",
LAST);
web_url("fckeditor.html",
"URL=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/topicAction_addUI.action?forumId={fids_2}",
"Snapshot=t6.inf",
"Mode=HTML",
EXTRARES,
"Url=../fckconfig.js", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=js/fckeditorcode_ie.js", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=../myconfig.js", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=lang/zh-cn.js", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/fck_editor.css", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/images/toolbar.collapse.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/images/toolbar.expand.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/images/toolbar.buttonarrow.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/images/toolbar.start.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=skins/default/fck_strip.gif", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
"Url=../fckstyles.xml", "Referer=http://localhost:8080/TestOA/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=bbs", ENDITEM,
LAST);
web_submit_data("topicAction_add.action",
"Action=http://localhost:8080/TestOA/topicAction_add.action",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost:8080/TestOA/topicAction_addUI.action?forumId={fids_2}",
"Snapshot=t7.inf",
"Mode=HTML",
ITEMDATA,
"Name=forumId", "Value={fids_2}", ENDITEM,
"Name=title", "Value=测试关联发帖标题", ENDITEM,
"Name=content", "Value=测试关联发帖内容", ENDITEM,
"Name=x", "Value=35", ENDITEM,
"Name=y", "Value=5", ENDITEM,
LAST);
return 0;
}