学习一种新知识,最先应该明白的是,我为什么要学习这个知识?自动关联与手工关联比的优劣是怎样的?需要下去后继续拓展学习~所以学习的重点围绕以下三个方面展开:
--自动关联和手工关联的对比
--如何发现哪里需要关联
--Web_reg_save_param
--实战演示
1、-自动关联和手工关联的对比
(1)自动关联是我们为关联设置规则,可以是具体的应用程序服务,这里的数据由所创建的规则替代。
(2)在手工关联中,我们想要关联的数值被扫描并且编写关联函数完成关联。Vugen内建自动关联引擎(auto-correlation engine),可以自动找出需要关联的值,并且可以利用关联函数自动建立关联。
(3)手动关联需要自行查找关联的对象,然后自行插入关联函数。
2、如何发现哪里需要关联
其实这里的难点就在于如何自行查找关联,通用的方法有两个:
(1)运用LR自带的工具win
(2)直接运用LR自带的扫描方式进行扫描。
详细展开来说的方法如下:
(1)首先回放扫描不同的值然后看哪些值需要关联。
(2)其次,录制两个脚本作比较,查看不同的文件决定需要关联的数据。
注:上面说的这个方法个人认为略陋,因为要保证两次录制过程完全一样,否则就失去了比较的意义,这个要求很严格。
3、Web_reg_save_param(详细信息记着查看帮助文档)
Web_reg_save_param函数可以将动态数据信息保存到一个参数中。在需要这个动态值的地方写上参数名就好。
4、实战演示(WebTours)
(1)将WebTours设置为可以关联的形式。
WebTours首页->点击链接administration->勾选 下图中所示选项->点击Update按钮即可。
(2)录制脚本,录制前进行相应配置。录制好的脚本如下(我用的录制工具为火狐浏览器,可能与IT录制出来的额有差异)
Action() { web_url("WebTours", "URL=http://127.0.0.1:1080/WebTours/", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=", "Mode=HTML", EXTRARES, "Url=http://addons.g-fox.cn/firstLocation.gif?p=false&a=false&e=false&bsp=1&r=0.29420363454916554", "Referer=", ENDITEM, LAST); web_url("header.html", "URL=http://127.0.0.1:1080/WebTours/header.html", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Mode=HTML", LAST); web_url("getcontentnew", "URL=http://front.meimotuan.com/api/getcontentnew?callback=jQuery18303228377563829057_1504150461298&guid=ZZ2FA3B363A1982A803A50A149BA5FAE&_=1504150461312", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Snapshot=t6.inf", "Mode=HTML", LAST); web_url("welcome.pl", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Snapshot=t7.inf", "Mode=HTML", LAST); web_add_cookie("renren_tag_0526=isTag; DOMAIN=127.0.0.1"); lr_think_time(18); web_submit_data("login.pl", "Action=http://127.0.0.1:1080/WebTours/login.pl", "Method=POST", "TargetFrame=", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Snapshot=t8.inf", "Mode=HTML", ITEMDATA, "Name=userSession", "Value=121842.888780883zczHcQDpfQVzzzzHDHzADpHzVff", ENDITEM, "Name=username", "Value=wang", ENDITEM, "Name=password", "Value=wang123456", ENDITEM, "Name=login.x", "Value=45", ENDITEM, "Name=login.y", "Value=6", ENDITEM, "Name=JSFormSubmit", "Value=on", ENDITEM, LAST); web_url("SignOff Button", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "TargetFrame=body", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t9.inf", "Mode=HTML", LAST); web_add_cookie("MSO=SID&1504150462&MSO_JSFormSubmit1&on&MSO_ServerErrorsProb&50&MSO_ServerLoadProb&50; DOMAIN=127.0.0.1"); web_add_cookie("MTUserInfo=firstName&wa&address2&beijing&username&wang&hash&39&lastName&ng%0A&address1&hebei&creditCard&88996688&expDate&11%2F12%0A; DOMAIN=127.0.0.1"); web_url("SignOff Button_2", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "TargetFrame=body", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", "Snapshot=t10.inf", "Mode=HTML", LAST); return 0; }
我们运用笨方法在重新录制一遍:脚本如下:
Action() { web_url("WebTours", "URL=http://127.0.0.1:1080/WebTours/", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=", "Mode=HTML", EXTRARES, "Url=http://addons.g-fox.cn/firstLocation.gif?p=false&a=false&e=false&bsp=1&r=0.20065038265620616", "Referer=", ENDITEM, LAST); web_url("header.html", "URL=http://127.0.0.1:1080/WebTours/header.html", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Mode=HTML", LAST); web_url("welcome.pl", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Snapshot=t3.inf", "Mode=HTML", LAST); web_url("getcontentnew", "URL=http://front.meimotuan.com/api/getcontentnew?callback=jQuery18305873143541948133_1504162732904&guid=ZZ2FA3B363A1982A803A50A149BA5FAE&_=1504162732916", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/", "Snapshot=t4.inf", "Mode=HTML", LAST); web_add_cookie("renren_tag_0526=isTag; DOMAIN=127.0.0.1"); lr_think_time(26); web_submit_data("login.pl", "Action=http://127.0.0.1:1080/WebTours/login.pl", "Method=POST", "TargetFrame=", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Snapshot=t5.inf", "Mode=HTML", ITEMDATA, "Name=userSession", "Value=121843.882786553zczHDttpHcAiDDDDDHzAtpAziDcf", ENDITEM, "Name=username", "Value=wang", ENDITEM, "Name=password", "Value=wang123456", ENDITEM, "Name=login.x", "Value=44", ENDITEM, "Name=login.y", "Value=2", ENDITEM, "Name=JSFormSubmit", "Value=on", ENDITEM, LAST); lr_think_time(5); web_url("SignOff Button", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "TargetFrame=body", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t6.inf", "Mode=HTML", LAST); web_add_cookie("MSO=SID&1504162733&MSO_JSFormSubmit1&on&MSO_ServerErrorsProb&50&MSO_ServerLoadProb&50; DOMAIN=127.0.0.1"); web_add_cookie("MTUserInfo=firstName&wa&address2&beijing&username&wang&hash&39&lastName&ng%0A&address1&hebei&creditCard&88996688&expDate&11%2F12%0A; DOMAIN=127.0.0.1"); web_add_cookie("Hm_lvt_dd4738b5fb302cb062ef19107df5d2e4=1487677640; DOMAIN=cclv.firefoxchina.cn"); web_url("SignOff Button_2", "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", "TargetFrame=body", "Resource=0", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", "Snapshot=t7.inf", "Mode=HTML", EXTRARES, "Url=http://cclv.firefoxchina.cn/cclv/v2/patterns.json", "Referer=", ENDITEM, LAST); return 0; }
此时我们得到两次录制的脚本,将其运用LR自带的工具进行比较:Tools-->compare with script。选择上次我们录制的脚本即可(当然要提前保存)。如下所示。凡是不一致的地方都会用黄色背景标出:
第二种发现关联的方法还是LR自带的方法:Vuser->Scan Script For Correlations(注意:执行前必须运行一次脚本才可以,否则无法直接运用此功能)
从上图中我们可以清楚的看到需要关联的地方为:name=userSession处。
下面就是如何书写关联函数Web_reg_save_param了,一般情况下对于菜鸟时期的我,经常会翻阅函数帮助文档位置在:Help-->Function Reference。
注意:补充个小常识:LR中的函数中带有reg(reg为register注册的缩写)的函数,一般使用的时候都放在Action脚本的头部。
手动添加的关联脚本如下:
lr_think_time(8); web_reg_save_param("login1", "LB=Name=userSession Value=", "RB=>", LAST ); //其中LB为左边界,RB为右边界
关联后运行脚本遇到如下问题:
Action.c(5): Error -26377: No match found for the requested parameter "login1". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size [MsgId: MERR-26377] Action.c(5): web_url("WebTours") highest severity level was "ERROR", 7675 body bytes, 2199 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26387]
网上看好多大神说是因为Web_reg_save_param这个函数所在的位置不对,应该放在返回信息前。好抽象,我推荐一种我解决问题的方法:用动态关联帮助定位,利用动态关联后会自动生成关联的脚本,然后在去写自己的手动关联脚本。
但是问题却没有得到解决?留下个疑问后面慢慢解决吧》》????