The provided code works correctly in LoadRunner VuGen or in LoadRunner Controller for one concurrent user. Here it is:
If you try to run this code with several concurrent users, all of them will try to create the same file and write to it. As a result, this will led to the error.
How to resolve this problem?Each user has to get unique file name and create a file with the unique name .
Now, I'm going to show - how to generate unique file name in LoadRunner.
The first step is to get a timestamp as a part of file name.
The timestamp consists of:
- date (month, day, year)
- time (hours, minutes, seconds, milliseconds)
The result of this code is:
These are Datetime Format Codes. Please, refer to a table for their descriptions:
|#||Datetime Format Code||Description|
month number (01-12)
day of month (01-31)
year, including century (for example, 1988)
The above code is not ideal. If you application (and LoadRunner script) saves more than one file per second, then file names will be dublicated.
That's why I can propose the code, which get a timestamp with milliseconds:
Let's execute this code and check the result:
Unfortunately, the chances that concurrent users will generate the same file name at the same time still exist.
To resolve this issue, we can get unique ids per virtual users. This can be done with lr_whoami LoadRunner function:
lr_whoami LoadRunner function returns information about the Vuser executing the script.
When you run this code in LoadRunner Vuser Generator, the result will be:
When you run this code in LoadRunner Controller, the result will be:
So, the last step is to combine timestamp with a vuser execution's ids and use them as a file name.
This will guarantee, that each LoadRunner virtual user will have unique file name.
So, the final code is:
Note: You can download this source code from here.
The result of above code is:
Using the generated name (05312008_221557_116_7_0_group1) you can save the file into "05312008_221557_116_7_0_group1.pdf" or "05312008_221557_116_7_0_group1.txt" depending on the file type.
- LoadRunner VIDEO - How to record PDF file saving?
- LoadRunner - How to record a file saving, performed by user from browser page?
- LoadRunner VuGen scripting - How to automatically download file from server and save it to local disk?
- How to perform basic operations on LoadRunner parameters?
- LoadRunner web_reg_find function - How to verify web page content?
I hope, this solution will help you in LoadRunner scripting.
Thank you for your attention, dear reader.