首页 文章

如何从LoadRunner调用Perl代码?

提问于
浏览
0

对不起,这是一个重复的问题;我找不到答案 . (是的,我查了一下,但我没有为LR 11.04进行RTFM . 我想保持我留下的稍纵即逝的理智 . )

我知道可以在loadrunner中调用Perl,但还没有找到一个例子 . 我知道这是可能的,因为Web_Reg_Save_Param_ex / Web_Reg-Save_Param_Regexp函数中的RegEx逻辑被移植到Perl子例程 .

我需要知道如何做到这一点,因为我需要对我们测试的(half - @ $$ ed)应用程序做很多事情 .

例如:

  • .NET应用程序 - 我可以快速轻松地查找参数值,在LR之外切片和解析它们,然后将值返回到LR .

  • 标准Web应用程序 - 对某人的沙箱进行第三方调用 . 所有信息均采用Base64编码 . 我们需要获取明文(在响应中提供),然后编码到Base 64,并将其发送到主系统 . 所以,AUT是系统A;系统A调用系统B(302响应),系统B响应,并且AUT将该数据发送回Systam A以存储在其数据库中 . (因为系统A和系统B来自同一个供应商 - 嗯,我对我们的招标过程有疑问,但它是OT . )

我有一个问题,我是一个优秀的程序员,但在Perl是一个菜鸟 . 所以我需要清除和重写,而不仅仅是坐下来编写代码 . 我查看了我能找到的RegEx信息(迄今为止最好的是using regular expressions in loadrunner),但到目前为止还不足以满足我的目的 .

资源:

{"text":"A*","value":"271"},  // This is just the pattern - it's repeated 320 times or so

示例代码段:

web_reg_save_param_ex(
    "ParamName=Charity1",
    "LB={\"text\":\"", 
    "RB/RE=\",\"value\":\"([0-9]+)\"},", 
    "Ordinal=All",
    SEARCH_FILTERS,
    "Scope=Body",
    "IgnoreRedirections=Yes",
    "RequestUrl=*/Person.aspx*",
    LAST);

那个工作,返回名称(上面的源代码为 A* ) .

web_reg_save_param_ex(
    "ParamName=Charity1",
    "LB/RE={\"text\":\"([A-Za-z0-9].+)\",\"value\":\"",
    "RB=\"},", 
    "Ordinal=All",
    SEARCH_FILTERS,
    "Scope=Body",
    "IgnoreRedirections=Yes",
    "RequestUrl=*/Person.aspx*",
    LAST);

这对我不起作用 - 找到的总记录,ZERO . 好吧,一个条目中有一个“ - ”,有些条目有空格 - 但100%失败? OTOH,如果我可以捕获整个列表,我会将它发送到Perl,拆分子串,并返回修剪和整齐的两个值,以保存为LoadRunner字符串(我认为 - LR不像一个单一的返回到目前为止,我可以做一个STRUCT并将值返回到那个,或者是指向内存空间的指针,并让LR将引用的内存读取到STRUCT,或类似的东西 . )

问题是,很明显AUT直接使用了这两个值,所以我以后不能使用它,当值被发回时 - 而且显然,NUMBERS比文本更重要 .

任何建议都表示赞赏,我想避免使用 system() ,但是 - 这是我对Base64问题的解决方法(它应该是唯一的Perl调用,永远 . )它工作很棒...直到我添加了一个 M$ 需要补丁,并且无法再在LoadRunner中打开和读取文件(惠普说,它帮助你 . 所以我删除了 M$ 补丁并运行了测试 . 它是2010年左右的可再发行版 . 那是2012年末 . 作为参考,我们're still running XP in this shop. I have a Core i5 with 4 GB on my desk here... Shipped with Win7. And we'重新运行Xtra Pathetic . 这里的Sanity供不应求......)

// ********** 后期修订版:

修改LoadRunner调用(到web_reg_save_param_regexp)后,我得到RegEx 's straightened out. Not clear why a 1583581 RegExp didn' t返回 A* 为第一个值,但我发现为什么 271 wasn 't showing up - that was easy, actually. The end value didn' t具有相同的边界条件 . 第一个值,显然是"Not Quote"在值中没有“ * ” . ???

web_reg_save_param_regexp(
"ParamName=Charity_REGEX",
"RegExp={\"text\":\"([^\"]{1,8})\",\"value\":\"", 
"Ordinal=All",
SEARCH_FILTERS,
"Scope=Body",
"IgnoreRedirections=Yes",
"RequestUrl=*/Person.aspx*",
LAST);

web_reg_save_param_regexp(
"ParamName=Tenants_REGEX",
"RegExp=\",\"value\":\"([0-9]{1,3})\"}",
"Ordinal=All",
SEARCH_FILTERS,
"Scope=Body",
"IgnoreRedirections=Yes",
"RequestUrl=*/Person.aspx*",
LAST);

1 回答

  • 2

    用于调用外部的项目(包括perl代码)system() . 您可能必须将perl项输出到您随后读回的文件中 . 或者,您可以将代码放在DLL中并使用lr_load_dll()调用它 .

    根据你的base64挑战,这里有一些你可能想要利用的base64函数 . 按原样提供,使用风险自负,不暗示支持或其他方式 . 我会说这个代码直接来自正在编码和解码的工作loadrunner虚拟用户 .

    static const unsigned char base64_table[64] =
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    
    
    unsigned char outbuf[BUFSIZE];
    
    unsigned char * base64_encode(unsigned char *src, size_t len,
                                  size_t *out_len)
    {
            unsigned char *out, *pos;
            const unsigned char *end, *in;
            size_t olen;
            int line_len;
    
            olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
            olen += olen / 72; /* line feeds */
            olen++; /* nul termination */
            if (olen >= BUFSIZE)
                {
                lr_message("ERROR:  required buffer size of %d versus fixed buffer of %d.\n",
                            olen, BUFSIZE);
                return NULL;
                }
            out = outbuf;
    
            end = src + len;
            in = src;
            pos = out;
            line_len = 0;
            while (end - in >= 3) {
                    *pos++ = base64_table[in[0] >> 2];
                    *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
                    *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)];
                    *pos++ = base64_table[in[2] & 0x3f];
                    in += 3;
                    line_len += 4;
                    if (line_len >= 72) {
                            *pos++ = '\n';
                            line_len = 0;
                    }
            }
    
            if (end - in) {
                    *pos++ = base64_table[in[0] >> 2];
                    if (end - in == 1) {
                            *pos++ = base64_table[(in[0] & 0x03) << 4];
                            *pos++ = '=';
                    } else {
                            *pos++ = base64_table[((in[0] & 0x03) << 4) |
                                                  (in[1] >> 4)];
                            *pos++ = base64_table[(in[1] & 0x0f) << 2];
                    }
                    *pos++ = '=';
                    line_len += 4;
            }
    
            if (line_len)
                    *pos++ = '\n';
    
            *pos = '\0';
            if (out_len)
                    *out_len = pos - out;
            return out;
    }
    
    
    unsigned char * base64_decode(unsigned char *src, size_t len,
                                  size_t *out_len)
    {
            unsigned char dtable[256], *out, *pos, in[4], block[4], tmp;
            size_t i, count, olen;
    
            memset(dtable, 0x80, 256);
            for (i = 0; i < sizeof(base64_table); i++)
                    dtable[base64_table[i]] = i;
            dtable['='] = 0;
    
            /*for (i = 0;  i < 256;  i++)
                printf("%d ('%c')\t%d ('%c')\n", i, i, dtable[i], dtable[i]);*/
    
            count = 0;
            for (i = 0; i < len; i++) {
                    if (dtable[src[i]] != 0x80)
                            count++;
            }
    
            //printf("count is %d\n", count);
            /*if (count % 4)
                    return NULL;*/
    
            /*  handle code missing the ender equals - russelladd   */
            //if (count % 4)
                    //printf("Input file with wrong number of valid characters.\n");
            for (i = 0;  i < count % 4;  i++)
                strcat(src, "=");
    
            count += (count % 4);
            /*  russelladd  */
    
            olen = count / 4 * 3;
            if (olen >= BUFSIZE)
                {
                lr_message("ERROR:  required buffer size of %d versus fixed buffer of %d.\n",
                            olen, BUFSIZE);
                return NULL;
                }
            pos = out = outbuf;
    
            count = 0;
            for (i = 0; i < len; i++) {
                    tmp = dtable[src[i]];
                    if (tmp == 0x80)
                            continue;
    
                    in[count] = src[i];
                    block[count] = tmp;
                    count++;
                    if (count == 4) {
                            *pos++ = (block[0] << 2) | (block[1] >> 4);
                            *pos++ = (block[1] << 4) | (block[2] >> 2);
                            *pos++ = (block[2] << 6) | block[3];
                            count = 0;
                    }
            }
    
            if (pos > out) {
                    if (in[2] == '=')
                            pos -= 2;
                    else if (in[3] == '=')
                            pos--;
            }
    
            *out_len = pos - out;
            return out;
    }
    

相关问题