...............
//將得到的內容存入日志用于檢查
lr_log_message("getvalue : %s",lr_eval_string ("{oldstate}"));
if ( lr_eval_string ("{oldstate}") == "正常"){
web_submit_data("modifyOfferingState.do",
"Action={url}/web/businessAccept/order/modifyOfferingState.do",
"Method=POST",
"RecContentType=text/html",
"Referer={url}/web/businessAccept/order/modifyOfferingStatePage.do?offeringId=
282172&offeringSpecId=1&offeringSpecName=普通寬帶(ADSL/LAN)&customerName=
{clientname}&nodeId=260000&pos1=定購管理&pos2=修改商品狀態",
"Snapshot=t24.inf",
"Mode=HTTP",
ITEMDATA,
"Name=offering.state", "Value=1", ENDITEM,
"Name=offering.recentModifyReason", "Value=修改原因", ENDITEM,
"Name=offering.customerId", "Value=281218", ENDITEM,
"Name=offering.offeringId", "Value=282172", ENDITEM,
"Name=offering.offeringSpecId", "Value=1", ENDITEM,
"Name=offering.recentMender", "Value=root", ENDITEM,
"Name=offering.recentModifyDatetime", "Value=2005-01-16", ENDITEM,
"Name=nodeId", "Value=260000", ENDITEM,
"Name=customerName", "Value={clientname}", ENDITEM,
"Name=offeringSpecName", "Value=普通寬帶(ADSL/LAN)", ENDITEM,
"Name=submit.x", "Value=33", ENDITEM,
"Name=submit.y", "Value=13", ENDITEM,
LAST);
}
Else
{
web_submit_data("modifyOfferingState.do",
"Action={url}/web/businessAccept/order/modifyOfferingState.do",
"Method=POST",
"RecContentType=text/html",
"Referer={url}/web/businessAccept/order/modifyOfferingStatePage.do?offeringId=
282172&offeringSpecId=1&offeringSpecName=普通寬帶(ADSL/LAN)&customerName=
{clientname}&nodeId=260000&pos1=定購管理&pos2=修改商品狀態",
"Snapshot=t24.inf",
"Mode=HTTP",
ITEMDATA,
"Name=offering.state", "Value=0", ENDITEM,
"Name=offering.recentModifyReason", "Value=修改原因", ENDITEM,
"Name=offering.customerId", "Value=281218", ENDITEM,
"Name=offering.offeringId", "Value=282172", ENDITEM,
"Name=offering.offeringSpecId", "Value=1", ENDITEM,
"Name=offering.recentMender", "Value=root", ENDITEM,
"Name=offering.recentModifyDatetime", "Value=2005-01-16", ENDITEM,
"Name=nodeId", "Value=260000", ENDITEM,
"Name=customerName", "Value={clientname}", ENDITEM,
"Name=offeringSpecName", "Value=普通寬帶(ADSL/LAN)", ENDITEM,
"Name=submit.x", "Value=33", ENDITEM,
"Name=submit.y", "Value=13", ENDITEM,
LAST);
}
從日志中截取的真實的返回內容為:
vuser_init.c(689): <tr bgcolor="#F6F6F6">\r\n
vuser_init.c(689): <td width="30%" height="23" align="right">\r\n
vuser_init.c(689): 原有商品狀態:</td>\r\n
vuser_init.c(689): <td width="70%" height="23"> 正常 </td>\r\n
vuser_init.c(689): </tr>\r\n
vuser_init.c(689): <tr bgcolor="#F4FBFE">\r\n
vuser_init.c(689): <td width="30%" height="23" align="right">\r\n
vuser_init.c(689): 修改后的狀態:</td>\r\n
vuser_init.c(689): <td width="70%" height="23">\r\n
vuser_init.c(689): \r\n
vuser_init.c(689): \r\n
vuser_init.c(689): \r\n
vuser_init.c(689): <input type="radio" name='offering.state' value='4' checked>
可以看到左邊界是:原有商品狀態:</td>,
右邊界是:</td>,偏移量為:57(包括了空格),
長度為:4(因為一個漢字長度為2),最后存入變量的值是:正常
4.經驗總結
1)為了便于腳本的調試,將返回的數據都寫入日志是個好辦法;
2)為了驗證取得的數據是否是自己期望的,可以將取得的數據寫入日志中進行驗證,
例:lr_log_message("getvalue : %s",lr_eval_string ("{oldstate}"));
3)因為它是一個注冊函數,必須在返回信息前使用,所以注冊的位置必須正確,否則很可能得到類似如下錯誤:
4)vuser_init.c(734): Error -27190: No match found for the requested parameter "oldstate".
Check whether the requested boundaries exist in the response data. Also,
if the data you want to save exceeds 1024 bytes,
use web_set_max_html_param_len to increase the parameter size [MsgId: MERR-27190]
5)vuser_init.c(734): Error -27187: The above "not found"
error(s) may be explained by header and body byte counts being 0 and 0,
respectively. [MsgId: MERR-27187]
6)vuser_init.c(734):
web_concurrent_end highest severity level was "ERROR" [MsgId: MMSG-27181]
7)所以使用手工方法,右鍵頁面確定在代碼中哪個位置之前注冊函數至關重要
8)如果腳本中中文為亂碼,可能是因為源文件的字符集和操作系統字符集不匹配。試試:
文章來源于領測軟件測試網 http://www.kjueaiud.com/