...............
//将得到的内容存入日志用于检查
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)如果脚本中中文为乱码,可能是因为源文件的字符集和操作系统字符集不匹配。试试:
文章来源于领测软件测试网 https://www.ltesting.net/