Use of the lr_save_string () function and the itoa () function in LoadRunner

Source: Internet
Author: User



Purpose: Use the For loop to add several regular data, such as: A1, A2, a3......a1000

Method: From the above view 1-1000 is an ordered sequence, and the front of a is fixed, so only need to use a for loop to loop out the 1-1000 can be.

However, LoadRunner uses the C language syntax, so you cannot add two variables directly (+) (+: hyphen) to the same as in Java .

So at this point you need to convert the int variable to string first, and then use the lr_save_string () function to save the variable in a parameterized way that LoadRunner can recognize, and then apply it to the recorded script.

Introduction to Functions:

int itoa (int value, char *str, int radix);


function Purpose: Convert int type to string

Parameter description: Value: Values of type int to convert

STR: target string, string value to be converted to STR


Radix: Radix 10 used to convert numbers: decimal, 2: Binary ...

int lr_save_string (const char *param_value, const char *param_name);

function Purpose: Save the Param_value value to the Param_name variable

Parameter description: Param_value: The value to save


Param_name: Variable Name

Question: Why use Itoa () and lr_save_string () two functions together.

Because the two parameters in lr_save_string () are pointers to type char, the value of type int must be converted to be used in the lr_save_string () function, so the itoa () and lr_save_string () Combined with two functions.





Action ()

{

int i;

Char str[100]; Defines an array to hold the value of the converted int type

for (i=0;i<=9;i++) {

Itoa (i,str,10);

Lr_save_string (str, "ID");

Lr_output_message ("==str:=%s==id:=%s====", Str,lr_eval_string ("{ID}"));

}








You can use Lr_save_string () to save the array to a variable and then apply it to the LoadRunner recorded script.


{ID}: is the way Loardrunner recognizes parameters



Web_url ("Login",

"url=http://server0.im.sonoro.cn:18001/login?username=a{id}&password=test&autologin=false& 1211433835878&1211433835878 ",

"Targetframe=",

"Resource=0",

"Reccontenttype=text/html",

"referer=http://server0.im.sonoro.cn:18001/proxy.html?1211433821547",

"Snapshot=t6.inf",

"Mode=html",

last);





return 0;

}


Copyright NOTICE: 51Testing Software Testing Network and related content provider owns all copyright of 51testing.com content, no person or entity may copy, reprint or mirror the contents of this website without express written permission. 51testing Software Testing Network Welcome to work with industry counterparts for useful cooperation and exchanges, if there is any relevant content of cooperation, please contact us.



The main function of the


Lr_eval_string () is to return the current value of one of the parameters in the script, and the return value type is char. Typically, the value of the output parameter is used when debugging a script. The following is the exact usage:
Lr_output_message ("the Parameter1 's value is%s ", lr_eval_string (" {parameter1} "), where the parameter parameter1 was previously defined. It is not possible to copy int data into a char array in your code. Please refer to the code of the building. 1 lr_eval_string (), eval should be an abbreviation for evaluate. The
function returns the value of the current parameter if it has only one parameter. Its arguments must be in the form of {Newparam}, which is the curly braces that are wrapped
apply: When you need to use parameterized content for each iteration. Lr_output_message ("Value:%s", lr_eval_string ("The row count is: {row_cnt}"));

For example: There is a parameterized value of int {Paraint} if it is wrong to directly use it as an int. Must Atoi (lr_eval_string ({paraint}))
So you cannot directly use an int variable as an argument.
2. How to implement "I want to convert iTemp into a string into a variable charr"
int itemp=3;
Char charr[1024] = {0};
//If not Unicode
itoa (itemp, Charr, 10  );
should be able

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.