Vugen: Loop Through An Array Of Parameters

I had a situation where I needed to find a specific record within a list. The web page had a list of 300 orders, and I had to find an order with a matching status of “NONE” based on some text displayed. The first thing I had to do was capture all the statuses and put them into an array, and then find a match.

To get the statuses into an array, I used the ORD=ALL argument with the web_reg_save_param function:

// Get all 300 orders displayed on this HTML page
 web_url( http://...get the page... );

To find an order with a status of “NONE”, I needed to access the array of parameter values by referencing their count (i.e. statusA_1, statusA_2, statusA_3, etc.), looping through and comparing the text value of them. Once I find one that matches the status of “NONE” , I break the loop.

for( i=1; i<301; i++)
 sprintf(status, "{statusA_%d}", i );
 lr_output_message(".....Looking for Status as NONE - %d - %s ",
     i, lr_eval_string(status) );
 if(!strcmp( lr_eval_string(status), "NONE"))
 lr_output_message("......Found Status as NONE....");

Once the status of the order is known, I figured I might need the order  number for something, so I created a variable with the parameter name that contains the order
number for the same order we found the status “NONE” for:

sprintf(order_num, "{orderID_%d}", i );
lr_output_message("i: %d OrderID: %s", i, lr_eval_string(order_num) );

Hopefully this helps you get a starting point for a similar situation. Let me know if you come up with alternative ways to do this in the comment section below.

What's Next?

Did you enjoy this article? Help spread the word by sharing:

Join the Northway Navigator Club today and get access to restricted content including our best tips and tricks. Membership is free! You will also receive free email updates by registering.

Engage in the conversation and leave a comment:

Scott Moore

About Scott Moore (153 articles)

With over 20 years of IT experience with various platforms and technologies, Scott has tested some of the largest applications and infrastructures in the world. He is a Certified Instructor and Certified Product Consultant in HP’s LoadRunner and Performance Center products. He currently holds HP certifications for ASE, ASC, and CI. A thought leader in the APM space, he speaks regularly at IT conferences and events


    Hello!, may be easy::::::
    int i;
    for(i=1; i <= statusA_count; i++){
    lr_output_message(lr_eval_string("{statusA_%d}", i);