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?
Well... May I start? :)
- 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:- lr_save_string("543210", "prmCounter");
- lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));
- i = atoi(lr_eval_string("{prmCounter}"));
- lr_output_message("Integer value of prmCounter: %d", i);
The result is:
The key line of code is: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 :)- i = atoi(lr_eval_string("{prmCounter}"));
- How to save integer number to LoadRunner parameter?
There are several way how to convert integer and save it to parameter.- lr_save_int function. It saves an integer to a parameter.
Code is very simple:- int i;
- i = 433;
- lr_save_int(i, "prmCounter");
- lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));
The result is: - sprintf function. It writes formatted output to a string. Then we use lr_save_string function to save the string to parameter:
- int i;
- char szBuf[12];
- i = 118;
- sprintf(szBuf, "%d", i);
- lr_save_string(szBuf, "prmCounter");
- lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));
The result is: - itoa function. It converts an integer to a string. And then we use lr_save_string function to save the string to parameter:
- int i;
- char szBuf[12];
- i = 27;
- itoa(i, szBuf, 10);
- lr_save_string(szBuf, "prmCounter");
- lr_output_message("String value of prmCounter: %s", lr_eval_string("{prmCounter}"));
The result is:
- lr_save_int function. It saves an integer to a parameter.
0 comments:
Post a Comment