LoadRunner script Development-parameterization to save content as parameters, parameter arrays, and parameter values get

Source: Internet
Author: User
Tags locale

Turn from: http://blog.sina.com.cn/s/blog_13cc013b50102v49c.html (view original)

A string that uses {} By default in Vugen is called a parameter

Note: The parameter must be in double quotation marks in order to use

To save a string as a parameter

Lr_save_string ("String want to Save", "Arg_name");

Example: Replacing a URL link that needs to be opened with a parameter

Action2 ()

{

Lr_save_string ("http://172.25.75.2:1080/WebTours/", "Web_site");

Open the login page

Web_url ("Webtours",

"URL = {Web_site}",//Run error//change to "url= {web_site}"

"Resource=0",

"Reccontenttype=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=html",

last);

return 0;

}

Operation Error:

ACTION2.C (6): error-27226:the "URL = http://172.25.75.2:1080/WebTours/" argument (number 2) is unrecognized or misplaced [msgid:merr-27226]

ACTION2.C (6): Web_url ("webtours") highest severity level was "ERROR", 0 body bytes, 0 header bytes [msgid:mmsg-26388]

Workaround:

"url = {Web_site}", there is a space between the URL and the equal sign "=", the space can be removed.

So using the lr_eval_string () function is also called using double quotes.

You can also do this in the following way

Action2 ()

{

Lr_save_string ("http://172.25.75.2:1080/", "Web_site");

Lr_save_string ("webtours/", "web_name");

Open the login page

Web_url ("Webtours",

"Url={web_site}{web_name}",

"Resource=0",

"Reccontenttype=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=html",

last);

return 0;

}

Gets the string table of the parameter value

You can use the Lr_eval_string function to get a string representation of a parameter value and then output the result using the Lr_output_message () function

Action2 ()

{

Lr_save_string ("http://172.25.75.2:1080/", "Web_site");

Lr_save_string ("webtours/", "web_name");

Lr_output_message (Lr_eval_string ("Get string representation of parameter value: {web_site}{web_name}"));

Open the login page

Web_url ("Webtours",

"Url= {web_site}{web_name}",

"Resource=0",

"Reccontenttype=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=html",

last);

return 0;

}

Note: If you want to get the first letter of the argument string, the same as C, you can: Lr_eval_string ("{param}") [0];

will be int type numbers are saved as parameters

Lr_save_int (Int_number, "Param_name")

For example:

Action2 ()

{

Lr_save_int (0, "Int_param");

Open the login page

Web_url ("Webtours",

"Url=http://172.25.75.2:1080/webtours/",

"Resource=0",

"Resource={int_parma}",

"Reccontenttype=text/html",

"Referer=",

"Snapshot=t1.inf",

"Mode=html",

last);

return 0;

}

Save the time as a parameter

Implemented by the Lr_save_datetime function.

Function Prototypes:

void Lr_save_datetime (const char *format, int offset, const char *name);

Format: Expected output date formats, such as:%Y,%m,%d,%x, etc.

Offset: Similar to some keyword constants that represent time:

Date_now-now date

Time_now-Now time

One_day-day time

One_hour-One Hour time

One_min-A-minute time

It is important to note that they can be used alone or in conjunction with

Current time Date_now + Time_now

Date_now-one_day, yesterday

Date_now+one_day-Tomorrow

Two days before the date

date_now-2* (One_day), date_now-2*24* (One_hour), date_now-2*24*60* (one_min)

2 hours after the time

time_now+2* (One_hour)

time_now+2*60* (One_min)

Name: Names of the parameters that you expect to save time to

Format Reference table:

Code

Description

%a

Day of week, using locale ' s abbreviated weekday names

%A

Day of week, using the locale ' s full weekday names

%b

month, using locale ' s abbreviated month names

%B

month, using locale ' s full month names

%c

Date and time as%x%x

%d

Day of Month (01-31)

%H

Hour (00-23)

%I

Hour (00-12)

%j

Number of day in year (001-366)

%m

Month Number (01-12)

%M

Minute (00-59)

%p

Locale ' s equivalent of AM or PM, whichever is appropriate

%s

Seconds (00-59)

%u

Week number of year (01-52), Sunday was the first day of the week. Week number was the first Week with four or more January days in it.

%w

Day of week; Sunday is day 0

%W

Week number of year (01-52), Monday was the first day of the week. Week number was the first Week with four or more January days in it.

%x

Date, using locale ' s date format

%x

Time, using locale ' s time format

%y

Year within century (00-99)

%Y

Year, including century (for example, 1988)

%Z

Time zone abbreviation

%%

To include the '% ' character in your output string

Example:

Action ()

{

Lr_save_datetime ("%x", Time_now, "time");

Lr_save_datetime ("%y-%m-%d", Date_now, "DATE");

Lr_save_datetime ("%y-%m-%d%x", Date_now+time_now, "datetime");

Lr_save_datetime ("%y-%m-%d", Date_now-one_day, "Yesterday");

Lr_output_message (the current time of the system is: {lr_eval_string));

Lr_output_message (lr_eval_string (the current date of the system is: {date}));

Lr_output_message (lr_eval_string ("Current date of the system, current time: {datetime}");

Lr_output_message (Lr_eval_string ("Yesterday's date: {yesterday}"));

return 0;

}

Operation Result:

Starting Iteration 1.

Starting action action.

ACTION.C (7): The current time of the system is: 12:27:54

ACTION.C (8): The current date of the system is: 2014-10-22

ACTION.C (9): current date of the system, current time: 2014-10-22 12:27:54

ACTION.C (10): Yesterday's date is: 2014-10-21

Ending action action.

Ending Iteration 1.

Save the content as a formatted parameter

lr_param_sprintf (Param_name,format,var1,var2,...);

Example:

Action2 ()

{

int index = 56;

Char *suffix = "txt";

lr_param_sprintf ("Newparam", "log_%d.%s", Index,suffix);

Lr_output_message ("The new file name is%s", lr_eval_string ("{Newparam}"));

return 0;

}

Operation Result:

Starting action Action2.

ACTION2.C: The new file name is Log_56.txt

Ending action Action2.

Save the contents to the parameter array

This concept lr9.x only after

The array of parameters must meet the following two conditions:

1. The parameters must be assigned in the order of the same name, followed by an underscore and a number.

2. The parameter array must have a parameter named _count to record the length of the array

Related functions:

LR_PARAMARR_IDX ()//Gets the value of the specified number parameter in the parameter array

Lr_paramarr_len ()//Get the length of the parameter array

Lr_paramarr_random ()//Get a random parameter from the parameter list

Example: To create an array of parameters to access a Web site, you can write the following code

Script development-parameterization to save content as parameters, parameter arrays, and parameter values get "title=" LoadRunner script development-parameterization to save content as parameters, parameter arrays, and parameter values get "border=" 0 ">

Description: A parameter array named website was created with a script, and the value of the parameter with number 2 was obtained.

Operation Result:

Script development-parameterization to save content as parameters, parameter arrays, and parameter values get "title=" LoadRunner script development-parameterization to save content as parameters, parameter arrays, and parameter values get "border=" 0 ">

Here: web_site= lr_paramarr_idx ("website", 2), equivalent: Lr_eval_string ("{website_2}");

Get parameter array length

Example:

Action2 ()

{

intarray_size = 0;

Char*arr_size_str = NULL;

Lr_save_string ("www.google.com", "website_1");

Lr_save_string ("www.google.com", "website_2");

Lr_save_string ("www.google.com", "website_3");

Lr_save_string ("www.google.com", "website_4");

Lr_save_string ("4", "Website_count");

Array_size = Lr_paramarr_len ("website");

Output integer

1. Save the result array_size as a parameter

Lr_save_int (Array_size, "arr_size");

2. Get the string representation of a parameter

Arr_size_str = Lr_eval_string ("{arr_size}");

Output results

Lr_output_message (ARR_SIZE_STR);

return 0;

}

Operation Result:

Script development-parameterization to save content as parameters, parameter arrays, and parameter values get "title=" LoadRunner script development-parameterization to save content as parameters, parameter arrays, and parameter values get "border=" 0 ">

Get a random parameter from the parameter list

Example:

Action2 ()

{

Char*web_site = NULL;

Lr_save_string ("www.google.com", "website_1");

Lr_save_string ("www.google.com", "website_2");

Lr_save_string ("www.google.com", "website_3");

Lr_save_string ("www.google.com", "website_4");

Lr_save_string ("4", "Website_count");

Web_site = Lr_paramarr_idx ("website", 2);

return 0;

}

Operation Result:

Script development-parameterization to save content as parameters, parameter arrays, and parameter values get "title=" LoadRunner script development-parameterization to save content as parameters, parameter arrays, and parameter values get "border=" 0 ">

Example: output each parameter sequentially

Action2 ()

{

int i= 0;

Lr_save_string ("www.google.com", "website_1");

Lr_save_string ("www.google.com", "website_2");

Lr_save_string ("www.google.com", "website_3");

Lr_save_string ("www.google.com", "website_4");

Lr_save_string ("4", "Website_count");

for (i=0; i

{

Lr_output_message (Lr_paramarr_idx ("website", I));

}

return 0;

}

Output results

Script development-parameterization to save content as parameters, parameter arrays, and parameter values get "title=" LoadRunner script development-parameterization to save content as parameters, parameter arrays, and parameter values get "border=" 0 ">

Storing parameters with pointer variables

Action2 ()

{

Char*pt = NULL;

Lr_save_string ("Hello World", "Param");

pt = "{param}";

Lr_output_message (PT);

Lr_output_message (Lr_eval_string (PT));

return 0;

}

Operation Result:

Script development-parameterization to save content as parameters, parameter arrays, and parameter values get "title=" LoadRunner script development-parameterization to save content as parameters, parameter arrays, and parameter values get "border=" 0 ">

LoadRunner script Development-parameterization to save content as parameters, parameter arrays, and parameter values get

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.