How to get LoadRunner iteration number - using LoadRunner parameter?

In some cases, you have to know the current iteration number, which is being executed.
It would be great to have something like lr_iteration_number() function. Unfortunately, LoadRunner does not provide that function...

In the present article, I will describe how to get a current iteration nunber, which is being executed in LoadRunner VuGen or Controller. Actually, I know two ways how to get current LoadRunner iteration number:
  1. LoadRunner parameter of 'Iteration Number' type
  2. Global variable, which should be incremented each iteration
Today, I will describe and explain first approach (parameter of 'Iteration Number' type). The second one (global variable) I will describe in the next article.


Well, we are starting:
  1. LoadRunner parameter of 'Iteration Number' type
    To insert new parameter into LoadRunner VuGen script, select 'Vuser/Parameter List...' menu item:
    'Parameter List' dialog will be opened.

    Then:
    • Click 'New' btn to create new LoadRunner parameter
    • Set parameter name (I named it as 'prmIterationNumber') and
    • Select its type - 'Iteration Number'
    Please, see the screen shot on these steps:
    'Iteration Number' type means that the parameter will be replaced with the current iteration number. This is logical.

    The default settings for just created parameter of 'Iteration Number' type will be:
    Here, you can change text format for the new LoadRunner parameter. In my case, I will use default settings.

    So, Click 'Close' btn in 'Parameter List' dialog. We've just created the new parameter.

    All we need is to use it.
    For that, insert the following code into your LoadRunner VuGen script:


    1. lr_output_message("Current iteration #: %s", lr_eval_string("{prmIterationNumber}"));


    Great! Now we are ready to execute our LoadRunner script. Since, we plan to test LoadRunner 'Iteration Number' parameter, edit LoadRunner Run-time Settings ans set 'Number of iteration' to 3 (or any other value you wish):

    Execute the script in LoadRunner VuGen and see results:
    As you can see, our parameter (prmIterationNumber) changes its value according to a number of current iteration. So, we can use it get current LoadRunner iteration number.

    To check the correctness, we have to execute our script in LoadRunner Controller and see results.
    I've create
    Controller scenario (5 users, 3 iterations) and executed it.
    Please, see the results for one user (they are analogous for others users):
    Again, we can get current LoadRunner iteration number.
    So, this solution works correctly both for LoadRunner VuGen and LoadRunner Controller.


    I explained the first solution on
    get current LoadRunner iteration number. I used standard LoadRunner parameter for that. In the next article, I will show how can we do the same without parameters - we will use global variable.

    So, keep tracking this blog :) I hope, I will be able to give you something new on automated testing.
    Also, please send your comments and questions... Your feedback is important for me!

    Thank you, my readers.
    Dmitry Motevich




Related articles:

How to minimize/maximize QTP window?

This is very useful feature - minimize QTP window before script execution. It allows to observe a desktop or an application under test wholly.

I will show and describe how to minimize (or maximize) QTP window programmatically - i.e. from QTP script.
Also, provided approach can be applied to minimize (maximize) any required window - Browser, Notepad, MS Word or Excel, and so on.


There are two ways to minimize QTP window:

  1. Using Minimize method of Window object
  2. Using QTP Application object - QuickTest.Application


These methods will contain several lines only and I hope that my explanations will be understandable.
So, let's explore!

  1. Using Minimize method of Window object
    You can use Minimize method of Window object to minimize QTP window (or any other).

    Let's see two cases - when a window is located in Object Repository (OR) and widows is not located in OR.

    • If a window is located in Object Repository (OR), then minimizing can be performed using the following code:

      1. hWnd = Browser("browser_name").GetROProperty("hwnd")
      2. Window("hwnd:=" & hWnd).Minimize


      In first line, we get window handle (hWnd) of Browser object . And then we pass this handle to Window object and minimize it.
      Obviously, that we can use the same approach to maximize window (use method):

      1. hWnd = Browser("browser_name").GetROProperty("hwnd")
      2. Window("hwnd:=" & hWnd).Maximize


    • If a window is not located in Object Repository (OR), then we can use some run-time object properties and descriptive programming to identify a window. For example, we can use window title.

      Please, see a screen shot of QTP window:QTP window title has a prefix - 'QuickTest Professional - ' followed by test name. I will use this prefix ('QuickTest Professional - ') with a mask:

      1. sTitleMask = "QuickTest Professional - .*"
      2. Window("regexpwndtitle:=" & sTitleMask).Minimize


      I use Regular Expressions.
      Mask
      ".*" means "match any characters zero or more times". So, this mask will identify QTP window, and this code will minimize it.

      The same approach can be applied to Browser.

      See a screen shot of this browser:

      In this case, browser has prefix 'Google - '. So, I will use it as the mask:

      1. sTitleMask = "Google - .*"
      2. Browser("regexpwndtitle:=" & sTitleMask).GetROProperty("hwnd")
      3. Window("hwnd:=" & hWnd).Minimize


      Well, you can use any approach you like. All of them work and minimize/maximize windows correctly.


  2. Using QTP Application object - QuickTest.Application
    Since this approach uses QuickTest Automation Object Model, it can be applied to QTP window only.

    There is a procedure, which minimizes QTP window:


    1. Sub MinimizeQTPWindow ()
    2.     Set     qtApp = getObject("","QuickTest.Application")
    3.     qtApp.WindowState = "Minimized"
    4.     Set qtApp = Nothing
    5. End Sub


    To minimize QTP window, just execute MinimizeQTPWindow () procedure:

    1. MinimizeQTPWindow


    For detailed information, I recommend to Read QTP Help > QuickTest Automation Object Model Reference.

Since QuickTest Automation Object Model does not use UI, second approach is more stable.
But first method is more flexible - it allows working with browsers and stand-alone windows.

In any case, I recommend to read and explore both approaches.



Do you have comments or questions on this or related QTP topics?
Please, send them and I will try to prepared detailed and informative article.

--
Thank you, my readers
Dmitry Motevich




Related articles:

LoadRunner Correlation - How to capture an array of dynamic data with web_reg_save_param function

Imagine, that server returns the following response:
(since blogspot.com doesn't show tags correctly, I'm reluctant to show server response as image) .

And we have to capture dynamic values of all IDs (underlined with green lines). These values can be used later - say, for LoadRunner script correlation.

As usual, several solutions exist :) Let's see them:

  1. Insert five web_reg_save_param functions using "Ord=1" (2, 3, ...) attribute:

    1. web_reg_save_param ("ID1Value", "LB= value=\"", "RB=\"", "Ord=1", LAST);
    2. web_reg_save_param ("ID2Value", "LB= value=\"", "RB=\"", "Ord=2", LAST);
    3. web_reg_save_param ("ID3Value", "LB= value=\"", "RB=\"", "Ord=3", LAST);
    4. web_reg_save_param ("ID4Value", "LB= value=\"", "RB=\"", "Ord=4", LAST);
    5. web_reg_save_param ("ID5Value", "LB= value=\"", "RB=\"", "Ord=5", LAST);


    Tips: Please, note that web_reg_save_param function does not perform correlation. web_reg_save_param function just registers a request for correlation from the next server response. That's why web_reg_save_param function should be placed before action functions, such as: web_url, web_submit_form, and others.

    Tips: Enable extended logging for LoadRunner parameters substitutions. It will be helpful for script debugging:

    OK, let's execute our script and see results - whether values will be captured or not:
    As you can see, web_reg_save_param functions executed correctly and parameters contain values.
    I would remind you that, we used "Ord" attribute. It indicates the ordinal position or instance of the match. Read LoadRunner Help on web_reg_save_param function for detailed info.

    Then, you can perform any operations with saved parameters (for instance, read article How to perform basic operations on LoadRunner parameters?)


    Another solution is to not use "Ord" attribute. Instead of it, we will extend boundaries to capture values from a server response.


  2. Insert five web_reg_save_param functions with extended boundaries:

    1. web_reg_save_param ("ID1Value", "LB=ID1\" value=\"", "RB=\"", LAST);
    2. web_reg_save_param ("ID2Value", "LB=ID2\" value=\"", "RB=\"", LAST);
    3. web_reg_save_param ("ID3Value", "LB=ID3\" value=\"", "RB=\"", LAST);
    4. web_reg_save_param ("ID4Value", "LB=ID4\" value=\"", "RB=\"", LAST);
    5. web_reg_save_param ("ID5Value", "LB=ID5\" value=\"", "RB=\"", LAST);


    I extended left boundaries and included ID1, ID2, etc with inverted quote. Since new boundaries will define values explicitly, we don't need use "Ord" attribute. That's why I deleted "Ord" attribute from web_reg_save_param function.

    Let's execute new code and see results:
    Values captured successfully! :) Ain't it fun? :)


    I think, now is a time to introduce third way how to capture an array of dynamic data.
    For that, we will use "Ord=All" attribute of web_reg_save_param function:


  3. Insert web_reg_save_param function using "Ord=All" attribute:

    1. web_reg_save_param ("IDValues", "LB= value=\"", "RB=\"", "Ord=All", LAST);


    It looks very simple, doesn't it? :) Let's execute it and see results:

    Values captured. Great!
    There are several important items and I would like to pay your attention:
    • We specified one web_reg_save_param function only with "Ord=All" attribute, and it captured all values.
    • Captured values were saved into parameters with automatically generated names.
      Please, note that I specified initial parameter name - "IDValues". Values were saved into parameters "IDValues_1", "IDValues_2", "IDValues_3", etc. So, an array of values were created.
    • Additional parameter was created automatically - "IDValues_count". It contains number of matches saved to the parameter array.

    Please, see this example - how to use "_count" LoadRunner parameter to iterate all items in a array of captured values:

    1. web_reg_save_param ("IDValues", "LB= value=\"", "RB=\"", "Ord=All", LAST);

    2. // get number of matches
    3. nCount = atoi(lr_eval_string("{IDValue_count}"));

    4. for (i = 1; i <= nCount; i++) {
    5.     // create full name of a current parameter
    6.     sprintf(szParamName, "{IDValue_%d}", i);

    7.     // output a value of current parameter
    8.     lr_output_message("Value of %s: %s",szParamName, lr_eval_string(szParamName));
    9. }


    And the result of execution is:
    (click to enlarge image).

    Using above example, you can simplify LoadRunner script correlation. If you have to capture an array of values from server response, do not forget about web_reg_save_param function only with "Ord=All" attribute.


Summary:
  • I provided several solutions how to perform correlation and capture an array of dynamic values.
  • Last solution (web_reg_save_param function using "Ord=All" attribute) is more simple and convenient.
  • One call of web_reg_save_param function can capture five, ten or hundred values and place them into an array of parameters.
    It is convenient - LoadRunner correlation becomes easier.


Do you have questions on LoadRunner correlation, my dear reader?
Ask me, and I will do my best to prepare exhaustive and detailed answer...

---
Thank you,
Dmitry Motevich



Related articles:

Broken links detection - LoadRunner tutorial

Today, I will describe how to use LoadRunner for broken links detection.

'Broken' link is 'not valid' link. This link usually returns 404 Error - "Page not found".
Another side of broken links is that images other resources are not displayed.

Using LoadRunner for broken links detection can be helpful, when you perform load testing of a site and you have to be sure, that all pages, images, applets, and other resources are available during the high server loading.

LoadRunner allows broken links detection during:
  1. Script recording
  2. Script execution
  1. Broken links detection during LoadRunner script recording
    You have to set appropriate recording options. For that, click 'Options...' button from 'Star Recording' dialog:

    'Recording Options' dialog opens. Here, set 'Add comment to script for HTTP errors while recording' option:
    Please, note that you can see a description of the 'Add comment to script for HTTP errors while recording' option.

    Now, you are ready to record your script. Click 'OK' button on 'Recording Options' dialog and start recording.

    If LoadRunner find any HTTP errors, it will include comment into VuGen script.
    My application had some problems - there were several broken links for images there. So, LoadRunner generated the following script (click the image to view enlarged):
    As you see, my application had several broken links to images and LoadRunner detected it successfully. Also, you can find the point, where these broken links were used. This is previous function - web_url.

    LoadRunner inserted comments, which describe all occurred HTTP errors. Comments contain URL and server response.
    Since you have server responses, you can determine reasons of HTTP errors.

    Tips:
    For detailed info on HTTP status codes read this article from wikipedia and this one from w3.org.
    Tips: Read about the most 'popular' HTTP status code - 404.


  2. Broken links detection during LoadRunner script execution
    LoadRunner can check broken links during the script execution too.
    You have to turn off one LoadRunner run-time option - 'Non-critical resource errors as warnings':
    Uncheck the 'Non-critical resource errors as warnings' option and execute previous script again.
    The result is:
    Please, note that LoadRunner's Replay Log contains errors about images we mentioned before. Their links were broken, that's why LoadRunner generated errors.

I hope, this LoadRunner tutorial was helpful.
As you can see, the initial task - broken links detection with LoadRunner - can be resolved in two ways.

You have to set appropriate option only. LoadRunner will do the rest :)



Related articles:


--
Dmitry Motevich,
waiting for your feedback, comments, and questions...

How to execute program on remote computer?

 
Several days ago I faced with a simple task - I had to execute program (automated QTP test in my case) on several remote computers.
My goal was simple - if I can execute scripts on my computer, then why don't we execute them on remote computers?


I think, this task is very interesting and practical, isn't it? :)

There was one condition. I tried to use "native" Windows solutions, which do not require additional installed software or libraries. I didn't want to use external soft, files, etc.

As a result, I found two solutions. Both of them use WMI:
  1. Win32_Process Class
  2. Win32_ScheduledJob Class
I will describe both of them.
Running ahead, I will say that I decided in favour of second solution (Win32_ScheduledJob class).


Let's explore these solutions, and compare them.
For clarity, I will show how to execute simple application (notepad.exe) on remote computer.

  1. Execute program on remote computer with Win32_Process сlass
    To create and start new process, I used Create method of the Win32_Process class.
    VBScript code is simple enough:

    1. strComputer = "."
    2. strCommand = "notepad.exe"

    3. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    4. Set objProcess = objWMIService.Get("Win32_Process")

    5. errReturn = objProcess.Create(strCommand, null, null, intProcessID)

    6. If errReturn = 0 Then
    7. Wscript.Echo "notepad.exe was started with a process ID: " & intProcessID
    8. Else
    9. Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
    10. End If


    String strComputer = "." means "local computer".
    So, the result of notepad starting on my local computer was:
    And notepad started on my computer! Great!

    Then I tried execute my script on remote computer (I set strComputer = "servername"). The result was:
    Script said, that the process was created.
    Indeed, process was created. It was shown in Task Manager on remote computer:
    But I didn't see it on a desktop of remote computer!
    Further investigations shown, that:
    For security reasons the Win32_Process.Create method cannot be used to start an interactive process remotely.

    Win32_Process class is very useful to create and execute batch tasks on remote computer. But it can be applicable for interactive processes.

    That's why I preferred the second way. I mean Win32_ScheduledJob сlass.


  2. Execute program on remote computer with Win32_ScheduledJob сlass
    By analogy, to create and start new process, I used Create method of the Win32_ScheduledJob class.
    VBScript code is :

    1. strComputer = "."
    2. strCommand = "notepad.exe"

    3. Const INTERVAL = "n"
    4. Const MINUTES = 1

    5. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    6. Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
    7. Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")

    8. objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
    9. errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)

    10. If errReturn = 0 Then
    11. Wscript.Echo "notepad.exe was started with a process ID: " & intJobID
    12. Else
    13. Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
    14. End If


    Create method of Win32_ScheduledJob сlass creates new scheduled job on computer. (Hm... Have I said a tautology? :) ) In script I specified the time when scheduled job should be executed - in one minute from now. For that i used standard VBScript function - DateAdd.

    Hint: Some time ago I wrote an article abount time/date functions in VBScript. Read it.

    The result of execution was excellent! It created
    scheduled jobs both on local and remote computer.
    This is result for remote computer is:

    In one minute, the notepad was started and shown on desktop of remote computer!
    I was happy :))


I hope, these two methods of remote application execution will be very helpful for you. Computer should calculate, human should think :)

So, I shown how to force your computers to work.
Do you have any ideas on how to force a human to think? :)

Summary:
If you have to run batch tasks, I think first method (Win32_Process Class) is simpler.
If you have to run interactive programs, use Win32_ScheduledJob Class.


--
Dmitry Motevich

How to select correct boundaries for web_reg_save_param LoadRunner function?

I will explain and show - how to select correct boundaries for web_reg_save_param LoadRunner function.

web_reg_save_param
is used for LoadRunner script correlation. That's why every load tester should study this function thoroughly, if you wish your scripts work correctly.

Imagine that the server returns the following part of HTML page:
HTML source codeNote: I will refer to this example later.

  1. What boundaries should be used in web_reg_save_param LoadRunner function to capture value of "ID1" (abcde)?

    The correct left boundary for web_reg_save_param function should be:
    • ID1" value="
    And right boundary for web_reg_save_param is:
    • "
    See the solution:

    Do you know why it is? I will explain in details.

    To find out the boundaries, we have to see texts located on the left and on the right.

    What is the text located on the left? There are several variants:
    • " (inverted comma)
      Actually, inverted comma cannot be used as left boundary, because it is located in several places in server's responce.
      So, we have to extend the left boundary:
    • =" (equal sign and inverted comma)
      These two characters also unusable, because it is located in several places too. For example, type="text" or value="abcde". So, we have to extend the left boundary again.
      So, I recommend to include unique part - ID1:
    • ID1" value="
      These string occurs one time in server's response. So, it can identify uniquely the value of "ID1" (abcde).

    Right boundary can be found easily. Since abcde is followed by inverted comma, we can assign inverted comma to right boundary. So, right boundary is ".

    We have found left and right boundaries, so the final web_reg_save_param function is:

    1. web_reg_save_param("pID1Value", "LB=ID1\" value=\"", "RB=\"", LAST);


    Hint: Since left and right boundaries contains inverted commas, we have to insert backslash before.
    Backslash followed by special characters are named Escape Sequences.

    Let's execute our code.
    For that, enable extended logging from Run-time Settings:

    The result of LoadRunner script execution is the following:

    As you can see, we specified correct boundaries for web_reg_save_param LoadRunner function. Value of ID1 has been captured correctly.

    Hint: Use lr_eval_string function to get captured value (value of LoadRunner parameter).
    An example:


  2. What boundaries should be used in web_reg_save_param LoadRunner function to user name (John Smith)?

    Using of web_reg_save_param LoadRunner function looks similar to previous example with a small difference - we have to extract user name from several lines:

    1. User name:
    2. John Smith
    3. bla-bla-bla


    How to process this case? Piece of cake :)

    Left boundary for user name is "User name:" text followed by a new line. In terms of C language, a new line is "\r\n". So, the left boundary is "User name:\r\n". Right boundary is a new line only - "\r\n".

    So, the final code, which can be used for LoadRunner script correlation, is:

    1. web_reg_save_param("pUserName", "LB=User name:\r\n", "RB=\r\n", LAST);


    The result of its execution is:

web_reg_save_param is a kind of "must know" LoadRunner function. The principle is simple - it tries parse server's response and find a text, located between left and right boundaries.

In next articles, I will show different variants how to use web_reg_save_param LoadRunner function for script correlation. So, keep tracking carefully :)



Related articles:


How to perform basic operations on LoadRunner parameters?

LoadRunner functions and scripts, containing in the present article, will be interested for LoadRunner beginners in the first place.

I will describe - how to perform basic mathematical operations on LoadRunner parameters:
  • How to convert LoadRunner parameter's value to integer number?
  • How to save integer number to LoadRunner parameter?
  • How to perform mathematical operations on LoadRunner parameter?
You can use this article as a LoadRunner tutorial on LoadRunner parameter operations.
Well... May I start? :)

  1. How to convert LoadRunner parameter's value to integer number?

    Actually, this is not a difficult task. We have to use 'atoi' function.
    'atoi' function converts a string to an integer value.

    Please, see the following code:

    1. lr_save_string("543210", "prmCounter");
    2. lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));

    3. i = atoi(lr_eval_string("{prmCounter}"));

    4. lr_output_message("Integer value of prmCounter: %d", i);


    The result is:
    The key line of code is:

    1. i = atoi(lr_eval_string("{prmCounter}"));

    We get parameter's string value using lr_eval_string function and after that atoi function converts it to int value. Apparently, it is easy :)


  2. How to save integer number to LoadRunner parameter?

    There are several way how to convert integer and save it to parameter.

    1. lr_save_int function. It saves an integer to a parameter.
      Code is very simple:

      1. int i;

      2. i = 433;
      3. lr_save_int(i, "prmCounter");

      4. lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));


      The result is:

    2. sprintf function. It writes formatted output to a string. Then we use lr_save_string function to save the string to parameter:

      1. int i;
      2. char szBuf[12];

      3. i = 118;
      4. sprintf(szBuf, "%d", i);
      5. lr_save_string(szBuf, "prmCounter");

      6. lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));


      The result is:

    3. itoa function. It converts an integer to a string. And then we use lr_save_string function to save the string to parameter:

      1. int i;
      2. char szBuf[12];

      3. i = 27;
      4. itoa(i, szBuf, 10);
      5. lr_save_string(szBuf, "prmCounter");

      6. lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));


      The result is:


  3. How to perform mathematical operations on LoadRunner parameter?

    Let's a parameter contains integer value and we have to double it (multiply by two).
    In this case, the algorithm is:
    1. Convert and save LoadRunner parameter to integer number
      We discussed this operation above.
    2. Multiply integer number by two
      H'm... Do you have guesses how to do it? :)
    3. Save new integer number to LoadRunner parameter?
      This operation was discussed above too.

    So, the final code is:

    1. int i;
    2. lr_save_string("11", "prmCounter");
    3. lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));

    4. i = atoi(lr_eval_string("{prmCounter}"));
    5. i *= 2;

    6. lr_save_int(i, "prmCounter");
    7. lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));


    And its result is:

So, as you can see, working with LoadRunner parameters is not difficult.

As usual - let me know, if you have some questions on this topic.
I will try to help you and provide detailed answer.

--
Yours faithfully,
Dmitry Motevich, speaking LoadRunner :)



Related articles:

What are LoadRunner parameter and parameterization?

 
This is a simple question - what is LoadRunner parameter?

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:
  1. "Name=username", "Value=jojo", ENDITEM,
  2. "Name=password", "Value=bean", ENDITEM,
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:
  • The simplest one is to record our script for each user.
    In this case, our pseudocode will look like:
  1. Login as jojo/bean
  2. Perform other actions under jojo/bean

  3. Login as bob/lcdm
  4. Perform other actions under bob/lcdm

  5. Login as dm/psswrd
  6. Perform other actions under dm/psswrd

  7. so on...
As you can see, our code is duplicated. Actually, this is not good idea (read this article to find out why it is).
  • We can remake our code:
  1. Loop - perform next actions for each user name and password
  2.     Read user name and password into {UserName} and {Password} variables
  3.     Login as {UserName} and {Password}
  4.     Perform other actions under {UserName} and {Password}
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:
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).

  • Declaration
    To declare stack variable you can just write:

    1. int i;

    This means, that name of variable is 'i', and its type is int. It's easy, isn't it?

    To declare LoadRunner parameter you have to:
    1. select string, to be replaced with a parameter
    2. right-click on the selected text
    3. 'Replace with a parameter'
      'Select or Create Parameter' dialog opens.

    4. Here, you can enter name of your parameter:
      Note, that you can see an original value as well ('jojo' in our case).

    5. 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:
    1. lr_save_string function

      1. lr_save_string("abCDEfgID", "prmProductID");
      2. 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:

      1. char *pszProductID = "abCDEfgID";
      2. lr_output_message("ID is: %s", pszProductID);


      The result will be the same:
      So, as you see, LR parameter is similar to standard variables.

    2. lr_save_int function

      1. lr_save_int(144, "prmCounter");
      2. lr_output_message("Counter: %s", lr_eval_string("{prmCounter}"));

      3. lr_save_int(-18, "prmCounter");
      4. lr_output_message("Counter: %s", lr_eval_string("{prmCounter}"));


      Result is:

      Again, we can write analogous code using stack variables:

      1. int i;
      2. char pszCounter[12];

      3. i = 144;
      4. itoa(i, pszCounter, 10);
      5. lr_output_message("Counter: %s", pszCounter);

      6. i = -18;
      7. itoa(i, pszCounter, 10);
      8. lr_output_message("Counter: %s", pszCounter);


      The result will be the same too:

I think, you've received evidence, that LR parameter is similar to a variable. So,
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.

--
Yours faithfully,
Dmitry Motevich, living in LoadRunner-city :)



Related articles: