VuGen : Contents

Posted by Onsoft Technologies

1.How to perform basic operations in 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:


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



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


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



0 comments: