Using parameters in Loadrunner VuGen script

Using parameters in Loadrunner VuGen script

Parameterizing is a powerful thing in LoadRunner!
Now, I'm going to demonstrate some tips and uses of them.

Well, imagine the following situation...

Let's we have created VuGen script, which emulates the one user:

The problem: script runs correctly in VuGen for one user, but it fails for several concurrent users. This happens since we recorded the VuGen script for the specific user:
I marked "username" and "password" parameters and values with red lines.
Application under test (AUT) does not allow several sessions of the same user.
So, if second concurrent VuGen user logs in to application, he gets an error:
The solution: to parameterize the VuGen script.

Implementation:
  1. Right click on a value we want to parameterize (in our case this is a username - "load1") and select "Replace with a parameter" menuitem:

  2. Name the new parameter as "UserName" and click OK btn:
    Please, pay attention to "Parameter type" combobox. It contains interesting possible types, such as: "Date/Time", Iteration Number, Random number, even XML, and others.
    I will not describe them in the present post... I hope, I will have a chance to describe parameter types later. In any case, it depends on the opinion of the blog readers :)

  3. Wow! the value "load1" will be changed with a UserName parameter:
    We have just added the new parameter! It's wonderful, isn't it, dear friend? :)
    But where can we specify the real values for our parameter? How to configure it?
    Let's continue...

  4. Right click on the just added parameter and select "Parameter properties":
    By the way, this menu allows others operations with parameters. You can:
    • "Restore original value (load1)"
      In other words, rollback your changes
    • "Replace more occurrences" This menuitem will find for the initial string ("load1") in the script and will propose to replace it with the new parameter ({UserName}).
      Tips: Please, use this feature carefully. For example, let's there is "http://server/load1.htm" link in the script. Here, "load1.htm" is a name of page, but user. "Replace All" will produce incorrect link - "http://server/{UserName}.

  5. "Parameter properties" will be shown:
  6. This dialog is a "heart" of any parameter. You can here:
    • specify the type of the parameter
    • create the pool of values for any parameter (add new values for any parameter)
    • specify, how the parameter will be changed against interations and users
    • and other different settings...

    Tips: You can open dat-file (UserName.dat) and edit its content in the Notepad or Excel. MS Excel is useful if file contains values for several parameters.

    Tips:
    I recommend to read the LR Function Reference, topic "Data Assignment and Update Methods for File/Table Parameters". It contains the excellent table describing Update and Data Assignement methods ("Update value on" combobox and "Select next row" combobox correspondingly). There are explanations with examples which describes - what settings should be applied for your case.

    In the issue, the filled dialog will look like:
    These settings specify:
    • the list of values to be used ("load1", "load2", "John21", etc.)
    • update method ("Once") and data assignment method ("Unique").
      The combination means: "The unique value assigned in the first iteration is used for all subsequent iterations of the Vuser"
      So, that's exactly the same we need.

  7. After that I perform the similar procedure (steps 1-6) for "Password" parameter:
    Please, note:
    • You can store parameters in the one dat-file. As for me, I prefer this way. Separating test data from the code is a good idea. And using one data-file is very convenient.
    • In this post I use two dat-file. Just for demonstration...

  8. Ooh! Everything is completed I hope. Now, we have to create a scenario, add parameterized LoadRunner VuGen script and execute it :)
    Here you are:
    All transactions passed. In other words, all concurrent user logged with their unique login/password combination. Each user had his own session.


The summary: Parameterizing allows simplify load/performance testing:
  1. Instead of writing a separate LoadRunner VuGen script for each virtual user, we added parameters for specific information (username & password) and used the one script for all users.
  2. Parameterizing allows decrease maintenance cost. If application under test is changed, one test should be updated for 100 (e.g.) users, but 100 tests for each user
  3. Supporting of tests is a real pleasure :) To add new user, a test has to update dat-files only.

All three advantages is the result of data-driven testing methodology.
I plan to describe later how to write data-driven tests, what concepts should be used, and so on.



Related articles:

23 comments:

Amar said...

Hi Dmitry Motevich,

I think your a master of LoadRunner because this information is very usefull for each and everybody and you provide this information to all without any bussiness.

I salute to you.

and eagly I am waiting for your input on global variables.

Thanks for this usefull information.

Regards,
Amar

Mark said...

Hi Dimitri
Your blog has helped me immensely in areas of Loadrunner such as correlation concepts.
Do you plan writing anything on when you have to write a script for multiple Vusers who each need to work on unique data within that script..
i.e in Banking scenario where say 100 Clerks are all creating a New Account at the same time..So each Account would be for a different Customer but the Operational Profile ( Create Account ) would be the same..can't quite see easier way of setting this scenario up in Controller without C programming knowledge.

Any direction appreciated

Dmitry Motevich said...

2Amar:
Actually, I'm not a master of LodRunner... Really.
What I did - I read LoadRunner Tutorial, Help, and other documetations carefully several times :)

sailu said...

Hi Dmitry,

I never write comments for any data i read in internet.Looking at the information u provided i felt i should thank u for such a detail description for the above scenario

Deepakwrites said...

Hi Dmitry Motevich,

I am able to execute the scripts for multiple users, however, i want to caputre the success messages in a seperate file.
ex. when a username and password is found correct and the application logs in with that, i need the following info on a seperate file: -
Username Password Successful


can you please help me on this...

Thanks
Deepak
deepaksh113@yahoo.com
deepaksharma113@gmail.com
deepak_sharma@mindtree.com

Dmitry Motevich said...

Sailu,
I'm glad that you were impressed by this article :)

Dmitry Motevich said...

Deepakwrites,
What is your question?

Please formulate it with all needed details

Malatesh said...

hi
i started using the loadrunner 9.1 for the performance testing of flex web applications ,according to hp ,this latest version of hp is supporting the flex application with AMF 3 protocol ,but what we use it HTTP protocol ,problem what i am facing is it is not showing the snapshots ,can u help me in this regards

Dmitry Motevich said...

Malatesh (September 4, 2008 10:06 AM),

Which snapshots?
What does it show instead?
Why do you think that it should show something? What do you expect to see?

So, you should provide additional info on your issue.

Naveen said...

Hi Dmitry,

I visited this blog for the first time and really found it very helpful. I am preparing for HP Loadrunner AIS certification exam.
Can you please explain the use of parameters apart from 'Data' and 'Table' type and in what scenario, the other parameters are useful along with the screenshots.

Thanks in advance.

Anonymous said...

Hi Dmitry,

Can you please explain all the parameters with example and screenshots except file and table type parameters.

Hope a quick reply.
Thanks a lot.

Anonymous said...

Hi Dmitry,

I am waiting for you reply on the above question.

Dmitry Motevich said...

Naveen (September 6, 2008 12:45 AM),
Anonymous (September 6, 2008 12:58 AM),
Anonymous (September 6, 2008 4:43 AM),

Please, motivate me to create such visual tutorials on LoadRunner parameters apart from 'Data' and 'Table' types
:)

Just think - why should I spend my time to create them? I hope, you will find a great motivation reason :)

Naveen said...

Hi Dmitry,

I just want to have a clear picture of all the parameters aloggwith the scenario in which they can be used. so if not video tutorial then could you please explain me the scenarios regarding the parameters.
It would be a great help.

Dmitry Motevich said...

Naveen (September 7),
I understand YOUR needs, but I'm not motivated to spend MY time to create such tutorials.
All these topics are explained in LoadRunner Help.

Anonymous said...

Hi Dmitry,

What is the difference between content type check and text check(verification chk)? because both of them search for the specified text in the web page.

Dmitry Motevich said...

Anonymous (September 12),
What do you mean with "text check(verification chk)"?

Anonymous said...

Dmitry,

By saying Text check (verification check), i mean "Web check" in LR. So what is the difference between 'Content Type' check and 'web check' in LR as both of them serach for the specified text.

Dmitry Motevich said...

to Anonymous (September 21),
Contentcheck is automatic checking for presense/absense of some text on a page.
'Webcheck' is checking using function. I.e. you have to add verifivation manually for each received page.

So, the difference is a usability :)
Contentcheck is a more simple way.
But 'Webcheck' is more customizable. You can code it as you want

Anonymous said...

Hi Dmitry,
Hi,
I am trying to put the loop the parameter names for SetValue={Parameter_1} in web_edit_value so that when I loop the "web_edit_value" for 'n' number of times it would set a new paramater value sequentially like :

1st loop --> SetValue={Parameter_1}
2nd loop --> SetValue={Parameter_2}
3rd loop --> SetValue={Parameter_3} and so forth.

I tried below code but getting a warning message "Warning: The string 'fieldvalue' with parameter delimiters is not a parameter."

i = atoi(lr_eval_string("{NumOfInputLines_Doc}"));
x=1;
while (i>0) {
lr_save_int(x, "Counter");

sprintf(fieldvalue, "PVValue_%d", x);

web_edit_field("PV{Counter})",
//"Snapshot=t18.inf",
DESCRIPTION,
"Type=text",
"Name=PV{Counter}",
"FrameName=workspaceBodyFrame",
"BrowserOrdinal=3",
ACTION,
"SetValue={fieldvalue}",
LAST);

lr_output_message ( "PV Values is %s", fieldvalue);
x++;
i--;

}
Any thoughts?
Krish

Dmitry Motevich said...

@Anonymous (Krish),
I think the error message is clear enough -
"Warning: The string 'fieldvalue' with parameter delimiters is not a parameter."

You should create 'fieldvalue' parameter to use.

Sangeeta said...

For the first time i hav visited the site and i found it very useful and userfriendly.

I have a doubt. 1. Can u plz tell me the use of "Select Next Row" and "Update Value on" with some examples.

2. Trrough a institute i got the LR 8.1 CD. Earlier it was working fine. But now while recording a senario am unable to get the recording script. What to do now. I have reinstalled the CD but still of no help. Did the license expired or something else happened. Please help me as am new to LR.

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.