以下是一个很典型的关联的例子:
我们先录制系统自带的订票系统的登陆和退出的代码:
Action() { web_url("WebTours", "URL=http://127.0.0.1:1080/WebTours/", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST); lr_think_time(4); web_submit_data("login.pl", "Action=http://127.0.0.1:1080/WebTours/login.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Snapshot=t2.inf", "Mode=HTML", ITEMDATA, "Name=userSession", "Value=104241.004374241fDzViQzpzzcfDcVHVpDHQQHf", ENDITEM, /*session号(随机的)*/ "Name=username", "Value=test1", ENDITEM, "Name=password", "Value=test1", ENDITEM, "Name=JSFormSubmit", "Value=on", ENDITEM, "Name=login.x", "Value=48", ENDITEM, "Name=login.y", "Value=10", ENDITEM, LAST); web_image("Search Flights Button", "Alt=Search Flights Button", "Snapshot=t3.inf", LAST); web_image("SignOff Button", "Alt=SignOff Button", "Ordinal=1", "Snapshot=t4.inf", LAST); return 0; }
录制完后,我们再次运行代码,报错:
Action.c(31): Error -27987: Requested image not found [MsgId: MERR-27987]
Action.c(31): web_image("Search Flights Button") highest severity level was "ERROR", 0 body bytes, 0 header bytes [MsgId: MMSG-26388]
这里报错是因为每次登陆时系统为其分配一个session号(随机的)(红色标注的代码),所以要对seesion做关联。
我们可以验证下:
将刚刚录制的代码保存,再录制一遍刚才的步骤,点击工具——》对比代码:
可以看到有三处不一样,第一处是userSession,后面是点击按钮时的x,y坐标。
1:自动关联:
a.点击Vuser->Scan Script for Correlations点击对比后的Correlate即可。
b.将Vuser->Run-Time Setting的日志设置设置成扩展日志,在回放日志里面找到<input type=hidden name=userSession value=104241.774564601fDzVQDzpcHQVzzzHDcVHVpzVHzHf>其实就是每次红色部分的内容不同,所以我们要关联它。
将代码前加上红色的函数,第一个参数是自己起的名字,LB是要关联部分的左边,RB是要关联部分的右边。将原来的value值用函数里面的第一个参数代替。
Action() { web_reg_save_param("sessionID","LB=userSession value=","RB=>",LAST); web_url("WebTours", "URL=http://127.0.0.1:1080/WebTours/", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST); lr_think_time(4); web_submit_data("login.pl", "Action=http://127.0.0.1:1080/WebTours/login.pl", "Method=POST", "RecContentType=text/html", "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", "Snapshot=t2.inf", "Mode=HTML", ITEMDATA, "Name=userSession", "Value={sessionID}", ENDITEM, "Name=username", "Value=test1", ENDITEM, "Name=password", "Value=test1", ENDITEM, "Name=JSFormSubmit", "Value=on", ENDITEM, "Name=login.x", "Value=48", ENDITEM, "Name=login.y", "Value=10", ENDITEM, LAST); web_image("Search Flights Button", "Alt=Search Flights Button", "Snapshot=t3.inf", LAST); web_image("SignOff Button", "Alt=SignOff Button", "Ordinal=1", "Snapshot=t4.inf", LAST); return 0; }
若有疑问或不正之处,欢迎提出指正和讨论。