Showing posts with label LR parameters. Show all posts
Showing posts with label LR parameters. Show all posts

LoadRunner VIDEO tutorial - Parameters part3 ('Select next row' = 'Unique')

Here is last part of LoadRunner video tutorial on working with LoadRunner parameters.
It explains different combinations of the parameter setting 'Select next row' = 'Unique'.

Note:

LoadRunner parameters #1 - video tutorial is available here.
LoadRunner parameters #2 - video tutorial is available here.


The present LoadRunner video tutorial covers the following:
  • Settings on Parameter List dlg
    Option 'Select next row' = 'Unique'
    Option 'Update value on' = 'Each iteration'
    Option 'Update value on' = 'Each occurrence'
    Option 'Update value on' = 'Once'
    Option 'When out of values' = 'Abort Vuser'
    Option 'When out of values' = 'Continue in a cyclic manner'
    Option 'When out of values' = 'Continue with last value'
    'Allocate Vuser values in the Controller'
  • How to view an output value of LoadRunner parameter
LoadRunner parameters explained
part 3 of 3 (Select next row = Unique)

LoadRunner VIDEO tutorial - Parameters part2 ('Select next row' = 'Random')

I've prepared the second part of LoadRunner video tutorial on working with LoadRunner parameters.
Note: First part of LoadRunner parameters - video tutorial is available here.

The present LoadRunner video tutorial covers the following:
  • How to create new LoadRunner parameter
  • Settings on Parameter List dlg
    Option 'Select next row' = 'Random'
    Option 'Update value on' = 'Each iteration'
    Option 'Update value on' = 'Each occurrence'
    Option 'Update value on' = 'Once'
  • How to view an output value of parameter
LoadRunner parameters explained
part 2 of 3 (Select next row = Random)

LoadRunner VIDEO tutorial - Parameters part1 ('Select next row' = 'Sequential')

I've prepared new LoadRunner video tutorial on working with LoadRunner parameters.
The present LoadRunner video tutorial covers the following:
  • How to create new LoadRunner parameter
  • How to use 'Simulate Parameter' feature
  • Settings on Parameter List dlg
    Option 'Select next row' = 'Sequential'
    Option 'Update value on' = 'Each iteration'
    Option 'Update value on' = 'Each occurrence'
    Option 'Update value on' = 'Once'
  • How to view an output value of parameter

Generating unique file name using LoadRunner parameter

I'm sure that my readers are the best readers in the world!
They are careful and they are great professionals. I constantly learn from them. Indeed!

I want to thank Tim for his comment on getting unique file name in LoadRunner.

Sure, there is very simple way to generate unique file name in LoadRunner using LoadRunner parameters.

How to do that?

We have to create three different types LoadRunner parameters:
  • Vuser ID
  • Iteration Number
  • Date/Time
  1. Open "Parameter List" dialog from "Vuser/Parameter list...":
  2. Add new LoadRunner parameter of "Vuser ID" type:
  3. Then add second LoadRunner parameter of "Iteration" type:
  4. And add third LoadRunner parameter of "Date/Time" type:
    (Click the image to enlarge it)

    Please, note that I added new Date/Time format - "%Y%m%d_%H%M%S.000".
    I described the meanings of %Y, %m, etc in this post. Point and three zeros (".000") means using of milliseconds.
    So, this Date/Time format produce a string like: 20080616_231514.953

  5. That's all. Now I add the following line of code:
    lr_output_message(lr_eval_string("{VuserID}_{Iteration}_{DateTime}"));
    The result of this line is:
    As you can see, we generated unique string for the current LoadRunner virtual user. You can use it to save the current file, for example as "1_1_20080616_232322.940.pdf".

Summary:

Using of LoadRunner parameters is easy enough.
LoadRunner provides several useful types of parameters. We used three of them:
  • Vuser ID
  • Iteration Number
  • Date/Time
Also, this way doesn't require strong programming knowledge. The code is small and compact (in our script it consists of 1 line).

Simple and useful!



Related articles:


Have you got interested materials or your own thoughts on LoadRunner?
Let's share them and help each other to improve our skills and knowledge!
You can send them to my email: Dmitry Motevich's email

Thank you in advance, dear readers.

--
Dmitry Motevich

How to save parameter value to other parameter in LoadRunner?

One my reader asked me - "How to save parameter value to other parameter in LoadRunner?". OK, there is a simple solution.

To save parameter value to other parameter you have to:
  1. Evaluate value of initial parameter
    Use lr_eval_string LoadRunner function.
  2. Save the evaluated string to a second parameter
    Use lr_save_string LoadRunner function.
Please, check the following code:
// save string value to initial parameter
lr_save_string("some string value", "prmStr1");
lr_output_message(lr_eval_string("Value of prmStr1: {prmStr1}"));

// save the evaluated value to second parameter
lr_save_string(lr_eval_string("{prmStr1}"), "prmStr2");
lr_output_message(lr_eval_string("Value of prmStr2: {prmStr2}"));
Let's execute this code and check the result:
(click the image to enlarge it)

As you can see, both parameters (prmStr1 & prmStr2) have the same values - "some string value".
So, we assigned the parameter value to other parameter successfully.


Related articles:


Do you have questions on this topic - working with LoadRunner parameters?
Feel free to post them in comments.

--
Dmitry

LoadRunner web_reg_find function - How to verify web page content?

 
When you perform load testing, you have to be fully confident, that your application works correctly. It may be very usefull to check UI of application - is it shown correctly or not.

This verification can be performed with 2 ways:
  1. Using LoadRunner content verification with web_reg_find function
  2. Running LoadRunner GUI Vusers (QTP or WR scripts)
The present LoadRunner tutorial describes content verifications with web_reg_find function. I will explain and show a usage of web_reg_find function, its attributes and result.

To get additional information about the seconds approach (running LoadRunner GUI Vusers), please read the article How to execute QTP script from LoadRunner?

  1. How to add LoadRunner content verification?
    Let's start with LoadRunner demo Web application - Web Tours.
    I will show how to check that a greeting 'Welcome to the Web Tours site' is shown on a start page:

    I've recorded a simple script on Web Tour application - it just opens a start page, logs in, and logs out:

    After that:
    • open the script in Tree View (with menu 'View/Tree View')
    • select initial step ('Url: WebTours')
    • select the text I would like to check on the page and
    • right mouse click:
    Use default seetings in 'Find Text' dialog:

    Then open your LoadRunner script in Script View (menu 'View/Script View') and you will see that web_reg_find function has been just added before the first function:


    1. web_reg_find("Text=Welcome to the Web Tours site", "Search=Body", LAST);
    2. web_url("WebTours", "URL=...", ...


    Please, note:
    web_reg_find function has been added before the page opening function (web_url)!
    This is because LoadRunner web_reg_find function does not search for text on a page, it just registers a search request for a text string on an HTML page.

    This is very important and I would like to pay your attention - web_reg_find function should be placed before the function, which loads a page.

  2. Description of web_reg_find function attributes
    The simplest web_reg_find function can look like:

    1. web_reg_find("Text=Welcome to the Web Tours site", LAST);


    This form means 'register a request to search for a "Welcome to the Web Tours site" text on a next Web page retrieved from a server.

    Attribute 'Text=' contains a text, that should be searched.
    If the check fails, the error is reported after the next action function executes:

    Attribute 'Search=' defines the scope of the search:
    • Body (default value) means to search in a body of server's response and its resources
    • Headers means to search within a pages headers
    • Noresource means to search in a body of HTML page retrived from server and do not searhc in its resources

    Example:
    Please, see a server response:
    The following web_reg_find function checks that server's name is 'Xitami':

    1. web_reg_find("Text=Server: Xitami", "Search=Headers", LAST);



    The next important attribute of web_reg_find function is 'SaveCount='. Use it to save a number of matches that were found.

    Let me show an example on this attribute and you will understand it.
    Imagine, that we have to get a number of 'A Coach class ticket for :' text on Itinerary page:
    The following code:
    • uses web_reg_find function with "SaveCount=" attribute (3rd line) before the Itinerary page loads
    • then loads Itinerary page (6th line)
    • extracts number of matches (8th line) and
    • compares it to an expected value (9th line):

    1. int nFound;

    2. web_reg_find("Text=A Coach class ticket for :", "SaveCount=TextPresent_Count", LAST);

    3. // open Itinerary page
    4. web_image("Itinerary Button", "Alt=Itinerary Button", LAST);

    5. nFound = atoi(lr_eval_string("{TextPresent_Count}"));
    6. if (nFound == 11)
    7.     lr_output_message("Correct number of 'Coach class ticket' text: %d", nFound);
    8. else
    9. {
    10.     lr_error_message("Incorrect number of 'Coach class ticket' text: %d", nFound);
    11.     return 0;
    12. }


    If you have additional info on 8th line:

    1. nFound = atoi(lr_eval_string("{TextPresent_Count}"));

    please, read my article How to perform basic operations on LoadRunner parameters?


    All previous examples generated errors when text was not present on a page. What about the case, when should check that a web page does not containa specific text, say 'Exception occurred'? For that we can use 'Fail=' attribute.

    Possibles values:
    • NotFound (default value) means to generate error if the text is not found on a page
    • Found means to generate error if the text is found on a page

    For example, the following web_reg_find function

    1. web_reg_find("Text=Error occurred","Search=Body", "Fail=Found", LAST);

    will fail only if a web page contains "Error occurred" text.
    If this text is not shown on a page, then function finishes successfully.

    Tip:
    use this approach to verify that your application work correctly under heavy load.

  3. 'Find Text' dialog for web_reg_find function
    You can generate all content verifications manually or with 'Find Text' dialog.
    I would recommend using of 'Find Text' dialog for LoadRunner beginners.

    For example, there is an analogous 'Find Text' dialog options for previous web_reg_find function example (with 'Error occurred'):

    As for me, I prefer writing web_reg_find function and its attributes manually.

  4. Other important info on web_reg_find function
    I understand, that the present article is not comprehensive :)

    So, what to read next?
    • Function Reference on web_reg_find function
      I didn't explain several features - text flags (light LoadRunner regular expressions), TextPfx/TextSfx attributes and so on.
    • Function Reference on web_find function
    • HP Knowledge base
--
Thank you, my readers.
Dmitry Motevich




Related articles:

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 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: