Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Transactions 如何从LR中的N个类似事务列表中随机选择1个事务?_Transactions_Loadrunner - Fatal编程技术网

Transactions 如何从LR中的N个类似事务列表中随机选择1个事务?

Transactions 如何从LR中的N个类似事务列表中随机选择1个事务?,transactions,loadrunner,Transactions,Loadrunner,我有LR脚本,它在Action部分包含了近20个类似的事务 脚本片段如下所示: lr_start_transaction("select random item in Methodology"); // 1st transaction web_url("Load Testing Terminology", "URL=http://***/Load_Testing_Terminology", "Resou

我有LR脚本,它在Action部分包含了近20个类似的事务

脚本片段如下所示:

        lr_start_transaction("select random item in Methodology");

    // 1st transaction
        web_url("Load Testing Terminology", 
            "URL=http://***/Load_Testing_Terminology", 
            "Resource=0", 
            "RecContentType=text/html", 
            "Referer=http://***/Methodology", 
            "Snapshot=t21.inf", 
            "Mode=HTML", 
            LAST);

    // 2nd transaction
        web_url("Concepts", 
            "URL=http://***/Concepts", 
            "Resource=0", 
            "RecContentType=text/html", 
            "Referer=http://***/Methodology", 
            "Snapshot=t22.inf", 
            "Mode=HTML", 
            LAST);

        ...
// (and so on till last transaction in transactions list)

        lr_end_transaction("select random item in Methodology",LR_AUTO);
对于执行的每个脚本,我只需要从该列表中选择一个事务


你能告诉我,我如何实现这个随机选择吗?

现在我需要从我的页面上的有用链接中获得1个随机链接。 条件是随机事务的名称应该从该事务的相对URL中获取,如下所示:

"random_link_relative_URL" =  "/index.php/What_are_the_Goals_of_Performance_Testing?"
本案例的代码如下所示:

Action()
    {
lr_start_transaction("open index page");

web_url("***", 
        "URL=http://{HOST}/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t19.inf", 
        "Mode=HTML", 
        LAST);
lr_end_transaction("open index page",LR_AUTO);

/* in link_name we are collecting elements of links array on Methodology page*/
/* in my case usefull links have the structure like this: 
    <p><a href="/index.php/Load_Testing_Terminology" title="Load Testing Terminology">Load Testing Terminology</a> 
and useless links have different HTML-code structure,
therefore we need to use LB and RB to limit useful HTML snippets like this:
/index.php/What_are_the_Goals_of_Performance_Testing */

web_reg_save_param("link_relative_URL", "LB/ic=<p><a href=\"", "RB=\" title", "ORD=all", LAST );

/* the array containing 21 items of link_relative_URL is created when the transaction Methodology is performed */
lr_start_transaction("Methodology");

web_url("Methodology", 
        "URL=http://{HOST}/index.php/Methodology", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://***/index.php", 
        "Snapshot=t20.inf", 
        "Mode=HTML",
        LAST);

lr_end_transaction("Methodology",LR_AUTO);


/* using `lr_paramarr_random` function we can choise 1 random link from array of link_relative_URL and save this random link from array to parameter colled random_link_relative_URL */
lr_save_string(lr_paramarr_random("link_relative_URL"),"random_link_relative_URL");

/* let's verify that {random_link_relative_URL} was saved */
`lr_output_message("random link is %s",lr_eval_string("{random_link_relative_URL}"));`

/* let's save the relative URL `random_link_relative_URL` to variable colled  `random_link_name` */
sprintf(random_link_name, lr_eval_string("{random_link_relative_URL}"));

/* start transaction random_link_name */
 lr_start_transaction(random_link_name);

/* using this sintax we will see the name of random link in requst's status */
        web_url(lr_eval_string("{random_link_relative_URL}"), 
        "URL=http://{HOST}{random_link_relative_URL}", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://{HOST}/index.php/Methodology", 
        "Mode=HTML", 
        LAST);

/* close transaction */
lr_end_transaction(random_link_name, LR_AUTO);

    return 0;
}
包含两个相关参数的20个字符串的列表
{name\u of_random\u link}
{URL\u of_random\u link}
放置在参数列表文件中。
{name_of_random_link}
从该列表中随机选择,
{URL_of_random_link}
被选择为“与URL_of_random_link相同的行”

现在我需要从我的页面上的有用链接中获得1个随机链接。 条件是随机事务的名称应该从该事务的相对URL中获取,如下所示:

"random_link_relative_URL" =  "/index.php/What_are_the_Goals_of_Performance_Testing?"
本案例的代码如下所示:

Action()
    {
lr_start_transaction("open index page");

web_url("***", 
        "URL=http://{HOST}/", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t19.inf", 
        "Mode=HTML", 
        LAST);
lr_end_transaction("open index page",LR_AUTO);

/* in link_name we are collecting elements of links array on Methodology page*/
/* in my case usefull links have the structure like this: 
    <p><a href="/index.php/Load_Testing_Terminology" title="Load Testing Terminology">Load Testing Terminology</a> 
and useless links have different HTML-code structure,
therefore we need to use LB and RB to limit useful HTML snippets like this:
/index.php/What_are_the_Goals_of_Performance_Testing */

web_reg_save_param("link_relative_URL", "LB/ic=<p><a href=\"", "RB=\" title", "ORD=all", LAST );

/* the array containing 21 items of link_relative_URL is created when the transaction Methodology is performed */
lr_start_transaction("Methodology");

web_url("Methodology", 
        "URL=http://{HOST}/index.php/Methodology", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://***/index.php", 
        "Snapshot=t20.inf", 
        "Mode=HTML",
        LAST);

lr_end_transaction("Methodology",LR_AUTO);


/* using `lr_paramarr_random` function we can choise 1 random link from array of link_relative_URL and save this random link from array to parameter colled random_link_relative_URL */
lr_save_string(lr_paramarr_random("link_relative_URL"),"random_link_relative_URL");

/* let's verify that {random_link_relative_URL} was saved */
`lr_output_message("random link is %s",lr_eval_string("{random_link_relative_URL}"));`

/* let's save the relative URL `random_link_relative_URL` to variable colled  `random_link_name` */
sprintf(random_link_name, lr_eval_string("{random_link_relative_URL}"));

/* start transaction random_link_name */
 lr_start_transaction(random_link_name);

/* using this sintax we will see the name of random link in requst's status */
        web_url(lr_eval_string("{random_link_relative_URL}"), 
        "URL=http://{HOST}{random_link_relative_URL}", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://{HOST}/index.php/Methodology", 
        "Mode=HTML", 
        LAST);

/* close transaction */
lr_end_transaction(random_link_name, LR_AUTO);

    return 0;
}
包含两个相关参数的20个字符串的列表
{name\u of_random\u link}
{URL\u of_random\u link}
放置在参数列表文件中。
{name_of_random_link}
从该列表中随机选择,
{URL_of_random_link}
被选择为“与URL_of_random_link相同的行”

考虑到下一次构建中链接的数量可能会更改为30或40或50或6,为什么要硬编码?您的脚本是否应该足够灵活,可以收集页面上的URL列表,然后为您随机选择一个


考虑使用标准关联方法将URL列表收集到一个数组中,然后选择其中一个数组元素以继续下一页。

考虑到链接数量在下一次构建中可能会更改为30或40或50或6,为什么要硬编码?您的脚本是否应该足够灵活,可以收集页面上的URL列表,然后为您随机选择一个


考虑使用标准的关联方法将URL列表收集到一个数组中,然后选择其中一个数组元素以继续下一页。

@James pullel,是的,我考虑过这种方法,我认为大体上你是对的。因为在我的例子中,链接集是稳定的,并且不是很大,所以我决定使用参数化的方法需要更少的时间来实现。@James滑轮,我开始了你的方法。我面临着下一个问题:如果我的网页不仅包含有用的链接,我如何从链接数组中删除这些无用的链接,因为我需要从有用链接数组中随机选择1个链接?“在这种情况下我该怎么办?”詹姆斯·皮勒,是的,我考虑过这种方式,我认为总的来说你是对的。因为在我的例子中,链接集是稳定的,并且不是很大,所以我决定使用参数化的方法需要更少的时间来实现。@James滑轮,我开始了你的方法。我面临着下一个问题:如果我的网页不仅包含有用的链接,我如何从链接数组中删除这些无用的链接,因为我需要从有用链接数组中随机选择1个链接?在这种情况下,我应该怎么做?@Basic,为其他人编写有用的信息可以比我更快地完成相同的任务。@Basic,因为在这种情况下,我用第一种方法解决了这个任务,然后改进了脚本并找到了第二种方法。我不明白你的目标,为什么你再次问,很明显:有些事情已经改变了-溶剂化需要改进/重新考虑。因此,当我找到它时,我分享了它——在这两种变体中,因为我在archieves中没有找到如何完成这项任务的答案。@Basic,当我收到一项任务时,我从来没有同时设置最终解决方案。所以,我顺理成章地添加了它们,当我得到新的溶剂时,我会发布它——以帮助其他人在同样的情况下找到答案。如果我想帮助别人,我应该详细解释我为什么这样做?好的,但我想请你恢复我的10点声誉。我以前在以前的主题中获得过它,所以在这个主题中减去它们是不公平的。对不起,我在这里没有找到私人消息,所以我被迫在这里给你写信。我把我所有的尝试放在一个位置。这个结果可以吗?谢谢。@Basic,为其他人编写有用的信息可以比我更快地完成相同的任务。@Basic,因为在本例中,我用第一种方法解决了此任务,然后改进了脚本并找到了第二种方法。我不明白你的目标,为什么你再次问,很明显:有些事情已经改变了-溶剂化需要改进/重新考虑。因此,当我找到它时,我分享了它——在这两种变体中,因为我在archieves中没有找到如何完成这项任务的答案。@Basic,当我收到一项任务时,我从来没有同时设置最终解决方案。所以,我顺理成章地添加了它们,当我得到新的溶剂时,我会发布它——以帮助其他人在同样的情况下找到答案。如果我想帮助别人,我应该详细解释我为什么这样做?好的,但我想请你恢复我的10点声誉。我以前在以前的主题中获得过它,所以在这个主题中减去它们是不公平的。对不起,我在这里没有找到私人消息,所以我被迫在这里给你写信。我把我所有的尝试放在一个位置。这个结果可以吗?非常感谢。