标签:style http color 使用 os strong
【摘要】利用实际案例说明如何使用Mercury LoadRunner提取包含在 HTML 页内的动态信息并创建参数。
【关键词】性能测试,压力测试,Mercury LoadRunner
在使用Loadrunner进行性能测试时,经常遇到一种情况,需要通过web页面修改某事务的状态。于是需要首先读出当前的事务的状态,再进行修改,此时便可以使用到web_reg_save_param了。可以通过它先将事务的状态读出写入一个自定义的变量中,根据变量的值来决定下一步的动作。
语法:
int web_reg_save_param(const char *ParamName, <list of Attributes>, LAST);
参数说明:
HTML_TO_URL : 将 HTML-encoded 资料转成 URL-encoded 资料格式
HTML_TO_TEXT : 将 HTML-encoded 资料转成纯文字资料格式
目的:取得页面中的商品状态,如果状态是正常态就改为注销态,否则改为正常态。
录制脚本使用的是URL based script
将返回的数据记录到日志
该页面上点击右键,选择属性
看到URL,对照录制下的脚本中有:
web_url("modifyOfferingStatePage.do",
"URL={url}/web/businessAccept/order/modifyOfferingStatePage.do?offeringId=
282172&offeringSpecId=1&offeringSpecName=普通宽带(ADSL/LAN)&customerName=
{clientname}&nodeId=260000&pos1=定购管理&pos2=修改商品状态",
"Resource=0",
"RecContentType=text/html",
"Referer={url}/web/businessAccept/order/orderMenu.do",
"Snapshot=t23.inf",
"Mode=HTTP",
LAST);
于是在这段代码前添加注册函数:
web_reg_save_param("oldstate",
"LB/IC=原有商品状态:</td>",
"RB/IC=</td>",
"Search=body",
"Ord=1",
"RelFrameId=1",
"SaveOffset=57",
"SaveLen=4",
LAST);
web_url("modifyOfferingStatePage.do",
"URL={url}/web/businessAccept/order/modifyOfferingStatePage.do?offeringId=
282172&offeringSpecId=1&offeringSpecName=
普通宽带(ADSL/LAN)&customerName={clientname}&nodeId=
260000&pos1=定购管理&pos2=修改商品状态",
"Resource=0",
"RecContentType=text/html",
"Referer={url}/web/businessAccept/order/orderMenu.do",
"Snapshot=t23.inf",
"Mode=HTTP",
LAST);
...............
//将得到的内容存入日志用于检查
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)如果脚本中中文为乱码,可能是因为源文件的字符集和操作系统字符集不匹配。试试:
祝各位好运。
转:web_reg_save_param的使用详解,码迷,mamicode.com
标签:style http color 使用 os strong
原文地址:http://www.cnblogs.com/lci05/p/3700173.html