Back to Blog

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!

Back to Blog