Reputation: 993
I want to upload a unique file every time a VUser script is ran (as in the # of vusers in the Controller scenario) and I found some examples on different forums and out them together to try to accomplice this task:
Action()
{
char command[100];
sprintf(command, “copy C:\\source_dir\\srcFile.txt C:\\source_dir\\srcFile-%s.txt”,
lr_eval_string (”{iteration_number}”));
system(command);
web_submit_data("FileUpload",
"Action={URL}",
"Method=POST",
"EncType=multipart/form-data",
"TargetFrame=",
"RecContentType=text/html",
"Mode=HTML",
ITEMDATA,
"Name=File", "Value=C:\\source_dir\\srcFile-%s.txt", "File=yes", ENDITEM,
LAST);
sprintf(command, “del C:\\source_dir\\srcFile-%s.txt”, lr_eval_string (”{iteration_number}”));
system(command);
return 0;
}
However this script does create 100 files each time and that is not what I want to accomplice. 1.How can I modify my script to create 100 unique files (once). 2.Then run the upload (web_submit_data function) once per VUser in the controller. 3.And then delete the files in the end?
Maybe put the file generation in the init and the file deleting in the end part of the VUser script?
Upvotes: 2
Views: 7200
Reputation: 341
I think your script is almost there. The problem I see is that you don't have a unique enough file name for the file you are creating. Each of your 100 users will start with the same iteration number.
You can try something like this, create a new parameter in the script's parameter list called 'vuser' and assign it the type 'Vuser ID'. This will populate as the number of the individual vuser when you run it in the controller. This will ensure your users don't step on each other while using the file. Add this to your file name like this:
sprintf(command, "copy C:\\source_dir\\srcFile.txt C:\\source_dir\\srcFile-%s%s.txt,
lr_eval_string ("{iteration_number}")
lr_eval_string ("{vuser}") );
This will work as long as all your users are in the same group in the Controller. If you use this across multiple groups then do the same thing by adding a 'Group Name' parameter to the file name.
Upvotes: 1
Reputation: 5682
You have a couple of options.
Upvotes: 2