Question

I have LR script, which contains near 20 similar transactions in Action section.

The snippet of script is here:

        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);

I need to select only 1 transaction from this list for each script performing.

Could you please advise me, how can I realize this random choice?

Was it helpful?

Solution

Why are you hard coding this at all, given that the number of links may change in the next build to 30 or 40 or 50 or 6? Shouldn't your script be flexible enough to collect the list of URLS on the page and then select one at random for you?

Consider standard correlation methods to collect the list of URLS into an array and then select one of the array elements for use to continue to the next page.

OTHER TIPS

Now I need get 1 random link from usefull links on my page Methodology. And the condition is that the name of random transaction should be gotten from relative URL of this transaction, like this:

"random_link_relative_URL" =  "/index.php/What_are_the_Goals_of_Performance_Testing?"

The code for this case is next:

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;
}

On the 1st step we will see the array of usefull links on Methodology page, on the 2nd - chosen random link, and on the 3rd - transaction which has name and URL of this random link.


The 2nd way.

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);


/* saves pages names as link_name on Methodology web page using limitations in HTML tag */
web_reg_save_param("link_name", "LB/ic=<a href=\"/index.php/", "RB=\" title", "ORD=ALL", LAST );

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);

/* select random link from links array on the page Methodology */
random_tr = lr_paramarr_random("link_name"); 

    return 0;
}

The way to solve this task may be next:

in Action section to write only 1 request with 2 parameters {name_of_random_link} and {URL_of_random_link}:

web_url("{name_of_random_link}", 
"URL={URL_of_random_link}", 
"Resource=0", 
"RecContentType=text/html", 
"Referer=http://***/Methodology", 
"Mode=HTML", 
LAST);

The list containing 20 strings of 2 related parameters {name_of_random_link} and {URL_of_random_link} is placed in parameters list file. {name_of_random_link} is randomly selected from this list and {URL_of_random_link} is selected as "the same line as URL_of_random_link".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top