Replacing
hard coded values in the script is called Parametrization.
Parametrization
helps in :
1. Reducing script size
2. Avoiding cache effect
I've reread LoadRunner VuGen User's Guide v9, trying to find the exact definition of LoadRunner parameter. That's strange, but LoadRunner Help does not contain the exact answer on this question.
In this article, I will answer basic questions, connected to LoadRunner parameters.
I think, LR beginners should study this article carefully :)
So, I recommend to read it, if you want to know:
I've reread LoadRunner VuGen User's Guide v9, trying to find the exact definition of LoadRunner parameter. That's strange, but LoadRunner Help does not contain the exact answer on this question.
In this article, I will answer basic questions, connected to LoadRunner parameters.
I think, LR beginners should study this article carefully :)
So, I recommend to read it, if you want to know:
- the definition of LoadRunner parameter
- LoadRunner parameter functions
- how to create parameter in LoadRunner VuGen script
- which types of LoadRunner parameter are available
- how LoadRunner processes parameters - gets and sets their values
- other key concepts, connected to LR parameters
OK, let's start.
I've recorded Web (HTTP/HTML) simple script on Web Tours demo web application. There are two first steps:
Please, notice that we use the following hard-coded username & password - jojo and jojo:
They are hard-coded in the script! This is important.
What should we do, if we want to execute our script sequentially for different users, for example for jojo/bean, then for bob/lcdm, dm/psswrd, and so on?
There are several solutions:
As you can see, our code is duplicated. Actually, this is not good idea (read this article to find out why it is).
So, what have I done?
I do not use hard-coded values (jojo/bean, bob/lcdm, dm/psswrd, and so on). Instead, we use special variables - {UserName} and {Password}. They are parameters.
The source code will look like:
I've recorded Web (HTTP/HTML) simple script on Web Tours demo web application. There are two first steps:
Please, notice that we use the following hard-coded username & password - jojo and jojo:
- "Name=username", "Value=jojo", ENDITEM,
- "Name=password", "Value=bean", ENDITEM,
What should we do, if we want to execute our script sequentially for different users, for example for jojo/bean, then for bob/lcdm, dm/psswrd, and so on?
There are several solutions:
- The simplest one is to record our script for each user.
In this case, our pseudocode will look like:
- Login as jojo/bean
- Perform other actions under jojo/bean
- Login as bob/lcdm
- Perform other actions under bob/lcdm
- Login as dm/psswrd
- Perform other actions under dm/psswrd
- so on...
- We can remake our code:
- Loop - perform next actions for each user name and password
- Read user name and password into {UserName} and {Password} variables
- Login as {UserName} and {Password}
- Perform other actions under {UserName} and {Password}
I do not use hard-coded values (jojo/bean, bob/lcdm, dm/psswrd, and so on). Instead, we use special variables - {UserName} and {Password}. They are parameters.
The source code will look like:
So, now we can answer:
Question: What is LoadRunner parameter?
The simple answer is:
LoadRunner parameter is a special variable.
Note: We will investigate parameters and I will provide more exact definition later.
Since LoadRunner parameter is a variable, then I compare it with standard stack-based variable from C language (for example - int i).
So, now you can ask:
Question: What's the difference between LR parameter and stack-based variables?
// That is the question (C) W. Shakespeare :)
OK, I will answer - the LoadRunner parameters simplify:
My article, describing LoadRunner parameter and parameterization, is up.
I hope, it was helpful :) Please, let me know...
In the next part, I will describe operations you can perform with parameters.
After that, I will explain - how LoadRunner parameterization is connected with correlation (this question was asked by Anonymous in his comment).
And, as usual, I'm waiting for your opinions.
If you have some questions or doubts - feel free to ask me
Question: What is LoadRunner parameter?
The simple answer is:
LoadRunner parameter is a special variable.
Note: We will investigate parameters and I will provide more exact definition later.
Since LoadRunner parameter is a variable, then I compare it with standard stack-based variable from C language (for example - int i).
- Declaration
To declare stack variable you can just write:
- int i;
To declare LoadRunner parameter you have to:- select string, to be replaced with a parameter
- right-click on the selected text
- 'Replace with a parameter'
'Select or Create Parameter' dialog opens. - Here, you can enter name of your parameter:
Note, that you can see an original value as well ('jojo' in our case). - Specify type of parameter
Parameter type is determined by the source of parameter data:
Once you specified name and type of parameter, you declared LoadRunner parameter.
The above declaration of parameter uses GUI ('Select or Create Parameter' dialog).
This is not the only approach. We can declare parameter and assign value with lr_save_ functions (lr_save_string, lr_save_int,lr_save_searched_string, lr_save_var, and lr_save_datetime).
See these examples:
- lr_save_string function
- lr_save_string("abCDEfgID", "prmProductID");
- lr_output_message("ID is: %s", lr_eval_string("{prmProductID}"));
Here, I define new parameter ("prmProductID") and assign a value ("abCDEfgID") to it. So, the parameter contains this value.
To make sure that the parameter contains correct value, please see the result of execution:
Please, note that we can write analogous code using a stack variable:
- char *pszProductID = "abCDEfgID";
- lr_output_message("ID is: %s", pszProductID);
The result will be the same:
So, as you see, LR parameter is similar to standard variables. - lr_save_int function
- lr_save_int(144, "prmCounter");
- lr_output_message("Counter: %s", lr_eval_string("{prmCounter}"));
- lr_save_int(-18, "prmCounter");
- lr_output_message("Counter: %s", lr_eval_string("{prmCounter}"));
Result is:
Again, we can write analogous code using stack variables:
- int i;
- char pszCounter[12];
- i = 144;
- itoa(i, pszCounter, 10);
- lr_output_message("Counter: %s", pszCounter);
- i = -18;
- itoa(i, pszCounter, 10);
- lr_output_message("Counter: %s", pszCounter);
The result will be the same too:
So, now you can ask:
Question: What's the difference between LR parameter and stack-based variables?
// That is the question (C) W. Shakespeare :)
OK, I will answer - the LoadRunner parameters simplify:
- Working with memory
That is, you don't have to know, how many bytes allocate for a current value of parameter.
You just use lr_save_string (for example) function, and LR allocates required number automatically. - Working with data sources
For example, you can indicate, that values of parameters will be stored in a file:
In this case, you don't have to write additional code for file processing. LoadRunner takes all routine procedures upon himself. For example - when and how update values from file, what is the current delimiter, and so on.
Actually, these features (working with memory and data sources) are very comfortable from user's side. That's why LoadRunner parameter is used so extensively.
My article, describing LoadRunner parameter and parameterization, is up.
I hope, it was helpful :) Please, let me know...
In the next part, I will describe operations you can perform with parameters.
After that, I will explain - how LoadRunner parameterization is connected with correlation (this question was asked by Anonymous in his comment).
And, as usual, I'm waiting for your opinions.
If you have some questions or doubts - feel free to ask me
No comments:
Post a Comment