LoadRunner VuGen: DO Loop Example

Most people who use Vugen and have a development background know loops. In C or most other programming languages, a loop is a loop. Sometimes in my classes I will ask students the main difference between a “do while” loop verses a “while” loop to see if they have that programming background. A “do” loop requires that the code you want to run does execute at least once before checking the condition to see if it should run again. But how about a real world example when scripting for a load test?

How about trying to click a refresh button on a web page while the status is in a “Running” status for an extended period of time? Yep, been there. In the loop below, once the status isn’t “Running” anymore, it fails. I want it to continue to the next step in the script instead of failing.

Here is the old code:

do {
 
    // click refresh code goes here
 
} while (web_reg_find("Text=Running", "Search=BODY", LAST));

Instead of doing a web_reg_find, it may be better to grab the status as a parameter with web_reg_save_param. As long as the string is found, the string length will be greater than zero, so the loop will continue to execute the code that will refresh the screen. When it is not found, the string is empty and the script continues on.

do {
    web_reg_save_param ("status", "LB=...", "RB=...", "Notfound=Empty", Last);
 
    // click refresh code goes here
 
} while (strlen(lr_eval_string("{status}")) > 0);

Enjoy!

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