How to get LoadRunner iteration number - using LoadRunner parameter?

In some cases, you have to know the current iteration number, which is being executed.
It would be great to have something like lr_iteration_number() function. Unfortunately, LoadRunner does not provide that function...

In the present article, I will describe how to get a current iteration nunber, which is being executed in LoadRunner VuGen or Controller. Actually, I know two ways how to get current LoadRunner iteration number:
  1. LoadRunner parameter of 'Iteration Number' type
  2. Global variable, which should be incremented each iteration
Today, I will describe and explain first approach (parameter of 'Iteration Number' type). The second one (global variable) I will describe in the next article.

Well, we are starting:
  1. LoadRunner parameter of 'Iteration Number' type
    To insert new parameter into LoadRunner VuGen script, select 'Vuser/Parameter List...' menu item:
    'Parameter List' dialog will be opened.

    • Click 'New' btn to create new LoadRunner parameter
    • Set parameter name (I named it as 'prmIterationNumber') and
    • Select its type - 'Iteration Number'
    Please, see the screen shot on these steps:
    'Iteration Number' type means that the parameter will be replaced with the current iteration number. This is logical.

    The default settings for just created parameter of 'Iteration Number' type will be:
    Here, you can change text format for the new LoadRunner parameter. In my case, I will use default settings.

    So, Click 'Close' btn in 'Parameter List' dialog. We've just created the new parameter.

    All we need is to use it.
    For that, insert the following code into your LoadRunner VuGen script:

    1. lr_output_message("Current iteration #: %s", lr_eval_string("{prmIterationNumber}"));

    Great! Now we are ready to execute our LoadRunner script. Since, we plan to test LoadRunner 'Iteration Number' parameter, edit LoadRunner Run-time Settings ans set 'Number of iteration' to 3 (or any other value you wish):

    Execute the script in LoadRunner VuGen and see results:
    As you can see, our parameter (prmIterationNumber) changes its value according to a number of current iteration. So, we can use it get current LoadRunner iteration number.

    To check the correctness, we have to execute our script in LoadRunner Controller and see results.
    I've create
    Controller scenario (5 users, 3 iterations) and executed it.
    Please, see the results for one user (they are analogous for others users):
    Again, we can get current LoadRunner iteration number.
    So, this solution works correctly both for LoadRunner VuGen and LoadRunner Controller.

    I explained the first solution on
    get current LoadRunner iteration number. I used standard LoadRunner parameter for that. In the next article, I will show how can we do the same without parameters - we will use global variable.

    So, keep tracking this blog :) I hope, I will be able to give you something new on automated testing.
    Also, please send your comments and questions... Your feedback is important for me!

    Thank you, my readers.
    Dmitry Motevich

Related articles:

How to minimize/maximize QTP window?

This is very useful feature - minimize QTP window before script execution. It allows to observe a desktop or an application under test wholly.

I will show and describe how to minimize (or maximize) QTP window programmatically - i.e. from QTP script.
Also, provided approach can be applied to minimize (maximize) any required window - Browser, Notepad, MS Word or Excel, and so on.

There are two ways to minimize QTP window:

  1. Using Minimize method of Window object
  2. Using QTP Application object - QuickTest.Application

These methods will contain several lines only and I hope that my explanations will be understandable.
So, let's explore!

  1. Using Minimize method of Window object
    You can use Minimize method of Window object to minimize QTP window (or any other).

    Let's see two cases - when a window is located in Object Repository (OR) and widows is not located in OR.

    • If a window is located in Object Repository (OR), then minimizing can be performed using the following code:

      1. hWnd = Browser("browser_name").GetROProperty("hwnd")
      2. Window("hwnd:=" & hWnd).Minimize

      In first line, we get window handle (hWnd) of Browser object . And then we pass this handle to Window object and minimize it.
      Obviously, that we can use the same approach to maximize window (use method):

      1. hWnd = Browser("browser_name").GetROProperty("hwnd")
      2. Window("hwnd:=" & hWnd).Maximize

    • If a window is not located in Object Repository (OR), then we can use some run-time object properties and descriptive programming to identify a window. For example, we can use window title.

      Please, see a screen shot of QTP window:QTP window title has a prefix - 'QuickTest Professional - ' followed by test name. I will use this prefix ('QuickTest Professional - ') with a mask:

      1. sTitleMask = "QuickTest Professional - .*"
      2. Window("regexpwndtitle:=" & sTitleMask).Minimize

      I use Regular Expressions.
      ".*" means "match any characters zero or more times". So, this mask will identify QTP window, and this code will minimize it.

      The same approach can be applied to Browser.

      See a screen shot of this browser:

      In this case, browser has prefix 'Google - '. So, I will use it as the mask:

      1. sTitleMask = "Google - .*"
      2. Browser("regexpwndtitle:=" & sTitleMask).GetROProperty("hwnd")
      3. Window("hwnd:=" & hWnd).Minimize

      Well, you can use any approach you like. All of them work and minimize/maximize windows correctly.

  2. Using QTP Application object - QuickTest.Application
    Since this approach uses QuickTest Automation Object Model, it can be applied to QTP window only.

    There is a procedure, which minimizes QTP window:

    1. Sub MinimizeQTPWindow ()
    2.     Set     qtApp = getObject("","QuickTest.Application")
    3.     qtApp.WindowState = "Minimized"
    4.     Set qtApp = Nothing
    5. End Sub

    To minimize QTP window, just execute MinimizeQTPWindow () procedure:

    1. MinimizeQTPWindow

    For detailed information, I recommend to Read QTP Help > QuickTest Automation Object Model Reference.

Since QuickTest Automation Object Model does not use UI, second approach is more stable.
But first method is more flexible - it allows working with browsers and stand-alone windows.

In any case, I recommend to read and explore both approaches.

Do you have comments or questions on this or related QTP topics?
Please, send them and I will try to prepared detailed and informative article.

Thank you, my readers
Dmitry Motevich

Related articles: