sunita manjreka Absent Member.
Absent Member.
2246 views

trying to execute just a section of the loadrunner script

Jump to solution
I have a loadrunner script that I want to run with 60vusers. The script opens a file, edits it, saves and then closes the file. if I want every 20th user to execute the save section of code is there any way I can put it in a if/while loop and then determine by the user executing it? I donot want the others to go in the save section of code
0 Likes
1 Solution

Accepted Solutions
Oliver Lloyd Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Here:

Action()
{
int myrandomnumber;
myrandomnumber = rand()%100;
[PUT ACTION CODE HERE]

if(myrandomnumber<20){
[PUT SAVE CODE HERE]
}
return 0;
}

You could use blocks like pra said but then you'd not only have duplicate code, which means more work for you, but you'd also have the fun of having to reset all your run time settings in the scenario when you make any changes.
Oliver

View solution in original post

13 Replies
Oliver Lloyd Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
There's various ways:

You could use lr_whoami() to get the vuser id but that won't work if you have other scripts running.

You could maybe use the iteration number and a simple formula to work out every 20th iteration. But you want the 20th user so...

You could just put this code into another action / function and have another group that has different Run Time Settings that calls this action whereas the other group doesn't

you could have two scripts and split users between them.

You could simply set a random if statement and use a percentage of 5%, so:
myrandomnumber = rand() % 100 + 1;
if(myrandomnumber < 6) then //that's 5% of the time blah blah.

Or you could use blocks in the RTSs (nastly things blocks though never did trust them)

Etc, etc. It all depends what EXACTLY you want to do.

By the way - don't write to files using C code in LoadRunner scripts, you'll end up getting file access errors. It's such a newbie error, you see it ALL the time. Use VTS, it's much better.

Hey, is THAT why you are posting this question, because you are getting file access errors and want to reduce the number of users writing to the same file at the same time?
Oliver
0 Likes
sunita manjreka Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Thanks for responding back so quickly. No I am not really doing file operations. It was just a way to describe my problem in a simplified manner. To elaborate my problem, I have 2 scripts in my scenario - Contributors and Reviewers
I have to do a 80-20% split with 60vusers. Out of these 80% contributors I want about say 1 user in every 20vusers to execute this piece of code.

easy eg would be on a website like amazon, have users going and browsing webpages, but say only 1 in every 10 users actually go and submit an order. How would I do this if I can manage with just 1 script and not have 2.

Also, the reason why I prefer having 1 script is maybe because it easier to change things and maintain it.

Thanks
Sunita
0 Likes
Oliver Lloyd Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
You lied! Shocking behavior. OK, so anyway, you want a script that executes up to a point and then for 5% of the time executes a certain section of code.

As I said before many options but the easiest is to have an if statement using a random number. I'm not about to do everything for you so just look in the help file for 'IF' and 'RAND' it's really not difficult.
Oliver
0 Likes
prasad81 Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Hi Sunita,


I hope this will help you.

U can make it as one script as follows.

Create two actions, First action keep the code until save and Second action should be the save code.

Now you want to execute first action 80%of the users and second action 20% of the users.

Goto RuntimeSettings --> RunLogic --> Under Run part u can observe action1 and action 2 now selct Run part --> click on properties --> Select Run Logic as Random in properties --> Click on ok --> Now by default it will show 50% each for both actions ---> Double click on them and change how much percentage u want to execute.

Let me know if you found any trouble to implement the same.

Regards,
Prasad GS
0 Likes
sunita manjreka Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Thanks Prasad. This was a great solution. But my qustin is if second script just has save and if we have set the run properties to run randomly to set the percentages, the script that has only save - will it run OK if its dependent on the other script which is doing everything but the save?
0 Likes
Oliver Lloyd Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Here:

Action()
{
int myrandomnumber;
myrandomnumber = rand()%100;
[PUT ACTION CODE HERE]

if(myrandomnumber<20){
[PUT SAVE CODE HERE]
}
return 0;
}

You could use blocks like pra said but then you'd not only have duplicate code, which means more work for you, but you'd also have the fun of having to reset all your run time settings in the scenario when you make any changes.
Oliver

View solution in original post

Oliver Lloyd Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Also, sunita, give some thought to having more than one script. You should have a range of scripts that cover the different logical areas of the application you are testing.
Oliver
0 Likes
sunita manjreka Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Thanks a bunch Oliver. I liked ur solution too..I will try them both out. Its just that when I am running the test for 15 mins I am really not seeing that 5% users getting in that code section when I use ur approach
0 Likes
Oliver Lloyd Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Trust me. It works.

Open a new script and run the code below. It'll show you how often the execution path goes into the 'save' section and how often not. Expect about an 80 / 20 split.

Action()
{
int myrandomnumber;
int i,save, dontsave;

for(i=0;i<100;i++){

myrandomnumber = rand()%100;

if(myrandomnumber<20){
save++;
}
else{
dontsave++;
}
}
lr_output_message("save: %d", save);
lr_output_message("dont_save: %d", dontsave);

return 0;
}
Oliver
0 Likes
sunita manjreka Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
I have a question now that I m running the way Prasad has described. When we have this structure
Login
Action1(5%)
Action2(75%)
Action3(20%)
Logout

and the test is scheduled to run for an hr, do we have login then the action section run for an hr and then a final logout?
0 Likes
prasad81 Absent Member.
Absent Member.

Re: trying to execute just a section of the loadrunner script

Jump to solution
Hi Sunita,

Keep your login section in vuser_init &
logout in vuser_end.

Regards,
Prasad GS
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.