根据使用手册内容可见,LR支持的关于Parameter Functions包括:



1、 lr_save_int & lr_eval_string:

lr_save_int_Func_lr_eval_string_Func()
{
lr_save_int(20, "param1");//保存整数到参数中
lr_output_message("lr_output_message=%s",lr_eval_string("{param1}"));//lr_eval_string返回脚本中的参数当前的值(从参数中取得对应的值,并且转换为一个字符串)。
return 0;
}

2、lr_save_string:

lr_save_string_Func()
{
char *tmp="hello";
lr_save_string("192.168.10.35","ip"); //将常量保存为参数ip
lr_save_string(tmp,"miao"); //将变量tmp保存为参数miao
lr_output_message(lr_eval_string("{ip}"));
lr_output_message(lr_eval_string("{miao}"));
return 0;
}

3、lr_save_var

lr_save_var_Func()
{
#define MAX_NAME_LEN 4
// Create the parameter, InName
lr_save_string("Fitzwilliam", "InName");
// Save the first four characters of "InName" to "ShortName"
lr_save_var( lr_eval_string("{InName}"),MAX_NAME_LEN, 0, "ShortName");//将可变长度的字符串保存为参数;
lr_output_message("ShortName value is %s", lr_eval_string("{ShortName}"));
return 0;
}

4、lr_save_timestamp

lr_save_timestamp_Func()
{
lr_save_timestamp("param", LAST );//时间戳以默认的13个字符的长度保存-历元时间加毫秒。
lr_output_message(lr_eval_string("{param}"));
lr_save_timestamp("param", "DIGITS=10", LAST );//保存时间戳,并指定10位数字的长度-纪元时间(以秒为单位)。
lr_output_message(lr_eval_string("{param}"));
lr_save_timestamp("param", "DIGITS=16", LAST );//保存时间戳,并指定16位数字的长度-纪元时间加微秒。
lr_output_message(lr_eval_string("{param}"));
return 0;
}
5、lr_save_datetime

lr_save_datetime_Func()
{
//void lr_save_datetime( const char *format, int offset, const char *name );将当前日期和时间分配给参数。
lr_save_datetime("Tomorrow is %B %d %Y", DATE_NOW + ONE_DAY, "next");//获取明天日期
lr_output_message(lr_eval_string("{next}"));
// Output: Action.c(4): Tomorrow is 四月 22 2021
lr_save_datetime("%Y-%m-%d", DATE_NOW, "dateReceived"); //按照"%Y-%m-%d"格式输出当前日期
lr_output_message(lr_eval_string("{dateReceived}"));
// Output: Action.c(7): 2021-04-21
lr_save_datetime("%m/%d/%Y %H:%M", DATE_NOW, "currDateTime0"); //按照"%m/%d/%Y %H:%M"格式输出当前时间
lr_output_message(lr_eval_string("{currDateTime0}"));
// Output: Action.c(10): 04/21/2021 10:10
lr_save_datetime("%Y-%m-%d %H:%M:%S", DATE_NOW, "currDateTime1"); //按照"%m/%d/%Y %H:%M"格式输出当前时间
lr_output_message(lr_eval_string("{currDateTime1}"));
// Output: Action.c(13): 2021-04-21 10:10:58
return 0;
}

6、lr_eval_json

lr_eval_json_Func()
{
//int lr_eval_json( "Buffer or Buffer/File = <buffer>", "JsonObject = <parameter name>" );
//从字符串或文件创建JSON对象。
char* json_input = "{"
""firstName": "John","
""lastName": "Smith","
""address": {"
" "streetAddress":"21 2nd Street","
" "city":"New York","
" "state":"NY","
" "postalCode":"10021""
"}"
"}";
lr_save_string(json_input, "JSON_Input_Param");
// Create a Json object from a string.
lr_eval_json("Buffer={JSON_Input_Param}",
"JsonObject=json_obj_1", LAST);
// // Create a Json object from a file.
lr_eval_json("Buffer/File=D:\LR TraningCourse\Functions\store.json",
"JsonObject=json_obj_2", LAST);
return 0;
}

7、lr_json_stringify

lr_json_stringify_Func()
{
char *json_input =
"{"
""cart":"
"{"
""customerId":1343,"
""lineItems":"
"[ {"productId":12343,"quantity":4}, "
" {"productId":39293,"quantity":2} ]"
"}"
"}";
lr_save_string (json_input, "JSON_Input");
lr_eval_json ("Buffer={JSON_Input}", "JsonObject=JSON_Param");
//compact
lr_json_stringify("JsonObject=JSON_Param","Format=compact","OutputParam=Result",LAST );
lr_output_message("Compact JSON is : %s", lr_eval_string("{Result}"));
//indented
lr_json_stringify("JsonObject=JSON_Param","Format=indented","OutputParam=Result",LAST );
lr_output_message("Indented JSON is : %s", lr_eval_string("{Result}"));
//auto
lr_json_stringify("JsonObject=JSON_Param","Format=auto","OutputParam=Result",LAST );
// Result is indented in VuGen and Compact on the Controller.
lr_output_message("Auto JSON is : %s", lr_eval_string("{Result}"));
return 0;
}
Vugen输出:


Controller输出:
8、lr_json_get_values

lr_json_get_values_Func()
{
//int lr_json_get_values( "JsonObject=<parameter name>", "ValueParam=<parameter name>", "QueryString=<JSON query>", ["SelectAll=<Yes|No>",] ["NotFound=<Error|Continue>",] LAST );
int i;
// See File: store.json
i = lr_eval_json("Buffer/File=D:\LR TraningCourse\Functions\store.json",
"JsonObject=s_json_obj", LAST);
//【1】 Single match
i = lr_json_get_values("JsonObject=s_json_obj",
"ValueParam=s_new_storename",
"QueryString=$.store.name",
LAST);
if (i != 1)
lr_error_message("lr_json_get_values should return %d, but returns %d", 1, i);
//【2】 Multi match with SelectAll=No
i = lr_json_get_values("JsonObject=s_json_obj",
"ValueParam=s_firstauthor",
"QueryString=$.store.books[*].author",
LAST);
if (i != 1)
lr_error_message("lr_json_get_values should return %d, but returns %d", 1, i);
lr_save_string("$.store.books[*].author", "s_path_author");
// Multi match with SelectAll=Yes
i = lr_json_get_values("JsonObject=s_json_obj",
"ValueParam=s_new_author",
"QueryString={s_path_author}",
"SelectAll=Yes",
LAST);
return 0;
}

9、lr_json_set_values

lr_json_set_values_Func()
{
int i;
// See File: store.json
i = lr_eval_json("Buffer/File=D:\LR TraningCourse\Functions\store.json",
"JsonObject=s_json_obj", LAST);
//【1】 Single match
i = lr_json_set_values("JsonObject=s_json_obj",
"Value="Red Books"",
"QueryString=$.store.name",
LAST);
if (i != 1)
lr_error_message("lr_json_set_values should return %d, but returns %d", 1, i);
// Test Get Values
i = lr_json_get_values("JsonObject=s_json_obj",
"ValueParam=s_new_storename",
"QueryString=$.store.name",
LAST);
if (i != 1)
lr_error_message("lr_json_get_values should return %d, but returns %d", 1, i);
//【2】 Multi match with SelectAll=No
i = lr_json_set_values("JsonObject=s_json_obj",
"Value="Ellie"",
"QueryString=$.store.books[*].author",
LAST);
if (i != 1)
lr_error_message("lr_json_set_values should return %d, but returns %d", 1, i);
i = lr_json_get_values("JsonObject=s_json_obj",
"ValueParam=s_new_firstauthor",
"QueryString=$.store.books[*].author",
LAST);
if (i != 1)
lr_error_message("lr_json_get_values should return %d, but returns %d", 1, i);
//【3】 Multi match with SelectAll=Yes
lr_save_string(""1111"", "s_author_1");
lr_save_string(""2222"", "s_author_2");
lr_save_string(""3333"", "s_author_3");
lr_save_string("3", "s_author_count");//待设置数据的个数,建议设置个数与实际数据的个数保持一致,否则出现如下异常情况:若不设置该项,则所有匹配项数据将设置为空;若该值为0,则报错提示没有找到匹配项;若该值为1,则所有匹配项均设置为第一个实际数据;若该值大于1且小于匹配数4,则按序获取实际数据进行匹配项设置;若该值大于等于匹配数4但是实际数据个数小于匹配数4,则按序获取实际数据进行匹配项设置,剩余匹配项设置为空;
lr_save_string("$.store.books[*].author", "s_path_author");
i = lr_json_get_values("JsonObject=s_json_obj",
"ValueParam=s_old_author",
"QueryString={s_path_author}",
"SelectAll=Yes",
LAST);
i = lr_json_set_values("JsonObject=s_json_obj",
"ValueParam=s_author",
"QueryString={s_path_author}",
"SelectAll=Yes",
LAST);
i = lr_json_get_values("JsonObject=s_json_obj",
"ValueParam=s_new_author",
"QueryString={s_path_author}",
"SelectAll=Yes",
LAST);
return 0;
}

10、lr_json_replace

lr_json_replace_Func()
{
int i = 0;
// See File: store.json
lr_eval_json("Buffer/File=D:\LR TraningCourse\Functions\store.json",
"JsonObject=r_json_obj", LAST);
/* Change "name": "Black Books" to "owner":"Mr Black".*/
i = lr_json_replace("JsonObject=r_json_obj",
"Value="owner":"Mr Black"",
"QueryString=$.store.name",
LAST);
if (i != 1)
lr_error_message("lr_json_replace should return %d, but returns %d", 1, i);
i = lr_json_get_values("JsonObject=r_json_obj",
"ValueParam=s_new_storename",
"QueryString=$.store.owner",
LAST);
lr_save_string("$.store.books[*].isbn", "r_path_isbn");
/*"discount": "20 percent"替换"isbn": "0-553-21311-3"和"isbn": "0-395-19395-8"*/
i = lr_json_replace("JsonObject=r_json_obj",
"Value="discount":"20 percent"",
"QueryString={r_path_isbn}",
"SelectAll=Yes",
LAST);
if (i != 2)
lr_error_message("lr_json_replace should return %d, but returns %d", 2, i);
i = lr_json_get_values("JsonObject=r_json_obj",
"ValueParam=r_discount",
"QueryString=$.store.books[*].discount",
"SelectAll=Yes",
LAST);
return 0;
}

11、lr_json_insert

lr_json_insert_Func()
{
int i = 0;
// See File: store.json
lr_eval_json("Buffer/File=D:\LR TraningCourse\Functions\store.json",
"JsonObject=i_json_obj", LAST);
// 1 match
i = lr_json_insert("JsonObject=i_json_obj",
"Value={"owner":"Mr Black"}",
"QueryString=$.store",
LAST);
if (i != 1)
lr_error_message("lr_json_insert should return %d, but returns %d", 1, i);
// 1 match with JsonNode
lr_save_string("{"isbn": "0-048-08048-9"}", "i_new_isbn");
lr_eval_json("Buffer={i_new_isbn}",
"JsonObject=i_json_obj2", LAST);
i = lr_json_insert("JsonObject=i_json_obj",
"JsonNode=i_json_obj2",
"QueryString=$.store.books[0]",
LAST);
if (i != 1)
lr_error_message("lr_json_insert should return %d, but returns %d", 1, i);
// 2 match with ValueParam and SelectAll=Yes
lr_save_string("{"discount":"20 percent"}", "i_new_discount");
i = lr_json_insert("JsonObject=i_json_obj",
"ValueParam=i_new_discount",
"QueryString=$.store.books[?(@.price > 10)]",
"SelectAll=Yes",
LAST);
if (i != 2)
lr_error_message("lr_json_insert should return %d, but returns %d", 1, i);
// 1 match
// Notice that both of the new items are inserted into the target array
i = lr_json_insert("JsonObject=i_json_obj",
"Value=[{"title":"New Book I"}, {"title": "New Book II"}]",
"QueryString=$.store.books",
LAST);
if (i != 1)
lr_error_message("lr_json_insert should return %d, but returns %d", 1, i);
lr_json_stringify("JsonObject=i_json_obj",
"OutputParam=i_result",
LAST);
return 0;
}

12、lr_json_find

lr_json_find_Func()
{
int i = 0;
// See File: store.json
i = lr_eval_json("Buffer/File=D:\LR TraningCourse\Functions\store.json",
"JsonObject=f_json_obj", LAST);
lr_json_stringify("JsonObject=f_json_obj",
"OutputParam=d_result",
LAST);
// Multi match with SelectAll=No
i = lr_json_find("JsonObject=f_json_obj",
"Value=fiction",
"QueryString=$.store.books[*].category",
LAST);
if (i != 1)
lr_error_message("lr_json_find should return %d, but returns %d", 1, i);
// Multi match with SelectAll=Yes
i = lr_json_find("JsonObject=f_json_obj",
"Value=fiction",
"QueryString=$.store.books[*].category",
"SelectAll=Yes",
LAST);
if (i != 3)
lr_error_message("lr_json_find should return %d, but returns %d", 1, i);
// Use RegExp
lr_save_string("$..books[?(@.price>10)].author", "f_path_author");
i = lr_json_find("JsonObject=f_json_obj",
"Value=.*Tolkien",
"QueryString={f_path_author}",
"UseRegExp=Yes",
LAST);
if (i != 1)
lr_error_message("lr_json_find should return %d, but returns %d", 1, i);
return 0;
}

13、lr_json_delete

lr_json_delete_Func()
{
int i = 0;
// See File: store.json
lr_eval_json("Buffer/File=D:\LR TraningCourse\Functions\store.json",
"JsonObject=d_json_obj", LAST);
lr_json_stringify("JsonObject=d_json_obj",
"OutputParam=d_result",
LAST);
// 1 match
i = lr_json_delete("JsonObject=d_json_obj",
"QueryString=$.store.name",
LAST);
lr_json_stringify("JsonObject=d_json_obj",
"OutputParam=d_result",
LAST);
if (i != 1)
lr_error_message("lr_json_delete should return %d, but returns %d", 1, i);
lr_save_string("$.store.books[*].isbn", "d_path_isbn");
// 2 matches
i = lr_json_delete("JsonObject=d_json_obj",
"QueryString={d_path_isbn}",
"SelectAll=Yes",
LAST);
if (i != 2)
lr_error_message("lr_json_delete should return %d, but returns %d", 2, i);
lr_json_stringify("JsonObject=d_json_obj",
"OutputParam=d_result",
LAST);
return 0;
}

13、lr_next_row


lr_next_row_Func()
{
lr_message( "Connect to Stock Trader ID Number %s",lr_eval_string("{ID}") );
lr_next_row("ID.dat");
lr_message( "Connect to Stock Trader ID Number %s", lr_eval_string("{ID}") );
lr_next_row("ID.dat");
lr_message( "Connect to Stock Trader ID Number %s", lr_eval_string("{ID}") );
return 0;
}

14、lr_read_file


读取txt文件:
lr_read_file_Func_textfile()
{
int res;
res = lr_read_file("D:\LR TraningCourse\Functions\ParameterFunctions\testfile\test1.txt", "test1", 0);
lr_message("res = %d
data = %s
", res, lr_eval_string("{test1}"));
return 0;
}

读取二进制文件:
lr_read_file_Func_binfile()
{
char *raw_data = 0;
unsigned long raw_data_len = 0;
int res;
res = lr_read_file("D:\LR TraningCourse\Functions\ParameterFunctions\testfile\test2.dat", "test2", 0);
lr_eval_string_ext("{test2}", 7, &raw_data, &raw_data_len, 0, 0, -1);
lr_message("res = %d
raw_data_len = %d
raw_data = %s", res, raw_data_len, raw_data);
return 0;
}

15、lr_param_sprintf

lr_param_sprintf_Func()
{
int index = 56;
char * suffix = "txt";
lr_param_sprintf ("LOG_NAME_PARAM", "log_%d.%s", index, suffix,100);
lr_output_message("The new file name is %s",lr_eval_string("{LOG_NAME_PARAM}"));
return 0;
}

16、lr_paramarr_len & lr_paramarr_idx

在机票示例程序中,web_submit_form调用返回的服务器信息中包含以下单选项:
<tr bgcolor="#EFF2F7"><td align="center"><input type="radio" name="outboundFlight" value="020;338;04/23/2021" checked="checked" >Blue Sky Air 020<td align="center">8am<td align="center">$ 338</TD></TR><tr bgcolor="#EFF2F7"><td align="center"><input type="radio" name="outboundFlight" value="021;301;04/23/2021">Blue Sky Air 021<td align="center">1pm<td align="center">$ 301</TD></TR><tr bgcolor="#EFF2F7"><td align="center"><input type="radio" name="outboundFlight" value="022;320;04/23/2021">Blue Sky Air 022<td align="center">5pm<td align="center">$ 320</TD></TR><tr bgcolor="#EFF2F7"><td align="center"><input type="radio" name="outboundFlight" value="023;277;04/23/2021">Blue Sky Air 023<td align="center">11pm<td align="center">$ 277</TD></TR></table>
为了预订航班,outboundFlight的value值是被需要的,因此需要使用web_reg_save_param来保存outboundFlight的value值。
保存单个字符串示例:
为了预订默认航班,含有“checked”的Value值,然后将它传给下一个web_submit_form,默认航班的HTML代码片段如下:
<input type="radio" name="outboundFlight" value="020;338;04/23/2021" checked="checked" >
保存所有匹配的值到数组outFlightVal,具体代码如下:
lr_paramarr_idx_and_lr_paramarr_len_Funcs()
{
int arrSize;
int ord;
char * FlightVal;
/*Correlation comment - Do not change! Original value='131151.632968813zHtzVVcpVcAiDDDDtAtHzpzHcHcf' Name ='userSession' Type ='ResponseBased'*/
web_reg_save_param_ex(
"ParamName=userSession",
"LB=name="userSession" value="",
"RB="/>
<table border",
SEARCH_FILTERS,
"Scope=Body",
"IgnoreRedirections=No",
"RequestUrl=*/nav.pl*",
LAST);
web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t32.inf",
"Mode=HTML",
LAST);
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/cgi-bin/login.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?in=home",
"Snapshot=t33.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={userSession}", ENDITEM,
"Name=username", "Value=jojo", ENDITEM,
"Name=password", "Value=bean", ENDITEM,
"Name=JSFormSubmit", "Value=on", ENDITEM,
"Name=login.x", "Value=0", ENDITEM,
"Name=login.y", "Value=0", ENDITEM,
LAST);
web_image("Search Flights Button",
"Alt=Search Flights Button",
"Snapshot=t34.inf",
LAST);
lr_think_time(4);
/*Correlation comment - Do not change! Original value='020;338;04/23/2021' Name ='outFlightVal' Type ='ResponseBased'*/
//get all Flights info
web_reg_save_param(
"outFlightVal",
"LB=name="outboundFlight" value="",
"RB="",
"ORD=ALL",
"SaveLen=18",
LAST);
web_submit_form("reservations.pl",
"Snapshot=t35.inf",
ITEMDATA,
"Name=depart", "Value=Denver", ENDITEM,
"Name=departDate", "Value=04/23/2021", ENDITEM,
"Name=arrive", "Value=London", ENDITEM,
"Name=returnDate", "Value=04/24/2021", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=roundtrip", "Value=<OFF>", ENDITEM,
"Name=seatPref", "Value=None", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=findFlights.x", "Value=52", ENDITEM,
"Name=findFlights.y", "Value=10", ENDITEM,
LAST);
arrSize = lr_paramarr_len("outFlightVal");//获取数组长度
lr_message("paramarr length=%d",arrSize);
FlightVal = lr_paramarr_idx("outFlightVal", arrSize);//获取索引为arrSize的值
// Submit a unique web request for each FlightVal in the Parameter array
for (ord=1; ord <= arrSize; ++ord) {
lr_save_string (lr_paramarr_idx("outFlightVal", ord), "flighVal");
web_url("reservations.lookup",
"URL=http://127.0.0.1:1080/cgi-bin/reservations.pl/lookup?resvKey={flighVal}",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Mode=HTML",
LAST);
}
return 0;
}

17、lr_param_unique

lr_param_unique_Func()
{
lr_param_unique ("OutParam");
return 0;
}

18、lr_param_increment

lr_param_increment_Func()
{
int i = 0;
lr_save_int(20, "modification_num");//保存整数到参数中
i=lr_param_increment("next_modnum", "{modification_num}");
lr_message("Return Vlues=%d",i);
return 0;
}

19、lr_zip & lr_unzip

lr_zip__lr_unzip_Funcs()
{
int i=0;
lr_save_string("This is the text I want to zip.", "param1");
i=lr_zip("target=param2", "source=param1");
lr_message("Return Vlues=%d",i);
i=lr_zip("source=param1", "target=param3");
lr_message("Return Vlues=%d",i);
i=lr_unzip("source=param3", "target=param4");
lr_message("Return Vlues=%d",i);
return 0;
}

20、lr_unmask

21、lr_checkpoint

22、lr_convert_double_to_double

lr_convert_double_to_double_Func()
{
lr_save_string("1.0502731456E7","sourceParam");
lr_save_string("10062731.0","sourceParam2");
lr_convert_double_to_double("sourceParam","%.2f","outparam");
lr_output_message("[%s] converted to: [%s]",lr_eval_string("{sourceParam}"),lr_eval_string("{outparam}"));
lr_convert_double_to_double("sourceParam","%.3f","outparam");
lr_output_message("[%s] converted to: [%s]",lr_eval_string("{sourceParam}"),lr_eval_string("{outparam}"));
lr_convert_double_to_double("sourceParam","%.0f","outparam");
lr_output_message("[%s] converted to: [%s]",lr_eval_string("{sourceParam}"),lr_eval_string("{outparam}"));
lr_convert_double_to_double("sourceParam2","%9.7E","outparam");
lr_output_message("[%s] converted to: [%s]",lr_eval_string("{sourceParam2}"),lr_eval_string("{outparam}"));
return 0;
}

23、lr_convert_double_to_integer

lr_convert_double_to_integer_Func()
{
lr_save_string("1.0502731456E7","sourceParam");
lr_save_string("10062731.0","sourceParam2");
lr_convert_double_to_integer("sourceParam","outparam");
lr_output_message("[%s] converted to: [%s]", lr_eval_string("{sourceParam}"),lr_eval_string("{outparam}"));
lr_convert_double_to_integer("sourceParam2","outparam");
lr_output_message("[%s] converted to: [%s]", lr_eval_string("{sourceParam2}"),lr_eval_string("{outparam}"));
return 0;
}

24、lr_convert_string_encoding

lr_convert_string_encoding_Func()
{
int rc = 0;
unsigned long converted_buffer_size_unicode = 0;
char *converted_buffer_unicode = NULL;
rc = lr_convert_string_encoding("Hello world", LR_ENC_SYSTEM_LOCALE, LR_ENC_UNICODE, "stringInUnicode");
if(rc < 0) {
// error
}
return 0;
}

妈呀,终于结束了,我要吐了...关于parameter functions部分内容就介绍到这里,部分函数示例待后续补充。。。
错误之处请欢迎指正~~