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:
- LoadRunner parameter of 'Iteration Number' type
- Global variable, which should be incremented each iteration
Well, we are starting:
- 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'
'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:- 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:
- What are LoadRunner parameter and parameterization?
- How to perform basic operations on LoadRunner parameters?
- Using parameters in Loadrunner VuGen script
- Using Correlation in LoadRunner scripts - visual tutorial
- LoadRunner Correlation - How to capture an array of dynamic data with web_reg_save_param function
- How to get LoadRunner iteration number - using LoadRunner parameter?
- All LoadRunner visual tutorials