How to get LoadRunner iteration number - using LoadRunner parameter?

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.

    Then:
    • 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:

13 comments:

Anonymous said...

Hi Motevich,
I am learning LR on my own. Earlier I used to refer support.mercury.com but since one month HP has stopped supporting Mercury's site and one need to has his/her own SAID no. to refer HP's site.
Unfortunately my company is still in negotiation phase regarding the license for LoadRunner, till that time I cant use the HP support site Can u tell me how can I get the SAID no or if possible you can help with your own?

Anonymous said...

Hi Dmitri,

Thanks lot for posting nice articles here, It is very informative and helpful. Can you post a article regarding finding Issues in the application using Loadrunner? I am looking for some article, which can explain like what all metrics need to monitored to find out the failure in system. I know, it is not a simple thing, one need to monitor many things like Resource Utilization, App side monitors, DB etc.., But I dont know what to monitor other than Resource Utilization. Someone asked me a question, what do you monitor when your load exceeds the limit and Login's start failing and timeouts occurs ? So can you come up with an Article which can help Loadrunner users to find out the Issues?

Unknown said...

hi motevich,

your artical is verynice, i get so much information in your artical,
thanks for u r information

Anonymous said...

Hi Dmitri,
I appreciate your effort in posting the article.however, i have a hands-on issue of 'converting' QTP scripts to Load Runner Scripts (Pl note that it's not about running the qtp scripts in LR). In other words, VB script action items need to be changed to LR script language. Could you help me in this regard?
Pl mail me on adis1427@gmail.com if u meet with any success.

Anonymous said...

Wow you articles on loadrunner is very great..
Sir iam Kiran
I am a bigger. I want to know about Performance Test Plan Document and who to create it, what are the things we need to collect requirement from the client. How to distribute load between tasks.

For example I am having 100 Vuser license. Can I run more then 100 V users? Any possibility. (Because I face this question every time)
If you post it I will be thank full to you.
My email id is saikiran.ganti@gmail.com

Anonymous said...

Wow you articles on Loadrunner is very great..
Sir
I am a Beginner. I want to know about Performance Test Plan Document and who to create it, what are the things we need to collect requirement from the client. How to distribute load between tasks.

For example I am having 100 Vuser license. Can I run more then 100 V users? Any possibility. (Because I face this question every time)
If you post it I will be thank full to you.
My email id is saikiran.ganti@gmail.com

Dmitry Motevich said...

Thank you, my readers for your comments!

Unknown said...

Your articles on LR & QTP are really great. I found your approach interesting. It is understandable to all levels of users.

Anonymous said...

Hi Motevich,

I came into this website today and found you give really nice informative knowledge. I would like to know how and when to use Random and Unique number in Parameter tyep. Like if we have to paramterize a value say amount which keeps on changing how do we do it?

Dmitry Motevich said...

@Anonymous,
I created 3 videos on LoadRunner parameters. They explain all LR params settings.
Please try to find them yourself... I'm sure it's not difficult :)

Anonymous said...

Hi Dmitry,
I've read your article about parameter but have a further question.
I create a script with parameter. Then I design a scenario with multiple Vuser to run this script. I try to run 1 iteration for each Vuser but hope each Vuser can call different value from parameter list. How can I do that?
Looking forward to hearing from you.
Thanks...

BR,
Fenny

Dmitry Motevich said...

@Fenny,
I created 3 videos about LoadRunner parameters. It is explained there how to resolve your issue.

Dmitry Motevich said...

Dear Readers!
Thank you very much for you comments!

Since this article was published more than one year ago, I've just disabled an adding of new comments for the article.