LR脚本编写时的几个小技巧

参数化空值

 

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

 

手工日志跟踪

    lr_set_debug_message(16|8,1);

    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(16|8,2);

 

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 > 0)   //把关联到的参数数组的每一个元素的值连起来
    {
        i = i + 1;   //i的初值为0
        strcat(szshippingMark," " );    //用一个空格进行连接
        strcat(szshippingMark,lr_paramarr_idx("param_correlation_shippingMark", i));     
        //lr_paramarr_idx:从关联变量数组中取出指定元素的值
        nshippingMark = nshippingMark - 1;

     }
     
     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");
     //------------------------------------------------------------------------------------

 

posted @ 2014-01-15 23:35  Defias  阅读(2332)  评论(1编辑  收藏  举报