LR脚本技巧

时间:2023-10-24 17:22:56

参数化空值

LR脚本技巧

如上图所示,当参数化时某个值需要为空值(非空格),直接在参数化文件中空一行/格即可,虽然Parameter List界面上没有显示空的那一行,但并不影响取值。

手工日志跟踪

    lr_set_debug_message(|,);

    web_submit_data("upload_8",
"Action=http://weblink-test.huawei.com/video/upload?method=Complete",
"Method=POST",
"RecContentType=text/html",
"Referer=http://weblink-test.huawei.com/video/video/videoColligation.do?method=uploadVideo",
"Mode=HTTP",
ITEMDATA,
"Name=fileUid", "Value={param_correnlation_fileUid}", ENDITEM,
...
LAST); lr_set_debug_message(|,);

LR中参数数组

参数数组的使用方法参考如下代码片段:

    web_reg_save_param_ex(
"ParamName=param_correlation_shippingMark",
"LB=input readonly=\"readonly\" value=\"",
"RB=\"",
"Ordinal=All",
SEARCH_FILTERS,
"Scope=BODY",
LAST); lr_start_transaction("GTM_ExpDecMaking_Edit"); web_submit_data("cntradeCustoms.do",
"Action=http://nkperf.huawei.com/ces/gtm/expcc/cntradeCustoms.do",
"Method=POST",
"RecContentType=text/html",
"Referer=http://nkperf.huawei.com/ces/gtm/expcc/cntradeCustoms.do?method=toDraftQuery&catalogId=11182",
"Snapshot=t7.inf",
"Mode=HTML",
ITEMDATA,
"Name=org.apache.struts.taglib.html.TOKEN", "Value={prama_correlation_token}", ENDITEM,
"Name=method", "Value=toEditCustoms", ENDITEM,
...
EXTRARES,
"URL=http://app.huawei.com/commonresource/newstyle/en/images/loading.gif", ENDITEM,
LAST); lr_end_transaction("GTM_ExpDecMaking_Edit", LR_AUTO); //--------------------------------------------------------------------------------
nshippingMark = lr_paramarr_len("param_correlation_shippingMark");
//lr_paramarr_len:取param_correlation_shippingMark关联变量数组的元素个数 while(nshippingMark > ) //把关联到的参数数组的每一个元素的值连起来
{
i = i + ; //i的初值为0
strcat(szshippingMark," " ); //用一个空格进行连接
strcat(szshippingMark,lr_paramarr_idx("param_correlation_shippingMark", i));
//lr_paramarr_idx:从关联变量数组中取出指定元素的值
nshippingMark = nshippingMark - ; } lr_save_string(szshippingMark,"shippingMark_param");
lr_convert_string_encoding(lr_eval_string("{shippingMark_param}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"shippingMark_param"); web_convert_param("shippingMark_param", "SourceEncoding=PLAIN",
"TargetEncoding=URL", LAST ); //转成URL码时,空格会转成加号:+ szshippingMark_P = ReplaceStr(lr_eval_string("{shippingMark_param}"),"+","&="); //将空格替换成:&= lr_save_string(szshippingMark_P,"shippingMark_param");
//------------------------------------------------------------------------------------