zl程序教程

您现在的位置是:首页 >  其它

当前栏目

loadrunner12.55:常用函数汇总说明之Information Functions参数函数

函数 常用 参数 说明 汇总 information Functions
2023-09-14 09:01:11 时间

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

lr_end_timer Stops a timer.
lr_get_host_name Returns the name of the host executing the script.
lr_get_master_host_name Returns the name of the machine running the LoadRunner Controller .
lr_get_vuser_ip Returns the IP address of the current Vuser. Not applicable for products that do not run Vusers.
lr_start_timer Starts a timer.
lr_user_data_point Records a user-defined data sample.
lr_user_data_point_ex Records a user-defined data sample and enables logging option.
lr_user_data_point_instance Records a user-defined data sample and correlates it to a transaction instance.
lr_user_data_point_instance_ex Records a user-defined data sample and enables logging option.
lr_whoami Returns information about a Vuser executing the script. Not applicable for products that do not run Vusers.

 1、lr_start_timer  &  lr_end_timer

lr_start_end_timer_Func()
{
	double wasteTime,trans_time;
	double time_elapsed;
	merc_timer_handle_t timer;

	int status;
	
	timer = lr_start_timer();
/*Correlation comment - Do not change!  Original value='131159.414823815zHtzfVcpttAtHQpAHtt' Name ='userSession' Type ='ResponseBased'*/
	web_reg_save_param_ex(
		"ParamName=userSession",
		"LB=name=\"userSession\" value=\"",
		"RB=\"/>\n<table border",
		SEARCH_FILTERS,
		"Scope=Body",
		"IgnoreRedirections=No",
		"RequestUrl=*/nav.pl*",
		LAST);

	/* result is in seconds */
	time_elapsed = lr_end_timer(timer);
	lr_output_message("Duration of web_reg_save_param_ex = %lf", time_elapsed);
	
	/* Subtract time spent on call web_reg_save_param from all open transactions. 
	Wasted time is measured in milliseconds */ 
	lr_wasted_time(1000 * time_elapsed); 
	
	web_url("WebTours", 
		"URL=http://127.0.0.1:1080/WebTours/", 
		"Resource=0", 
		"RecContentType=text/html", 
		"Referer=", 
		"Snapshot=t8.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=t9.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=t10.inf", 
		LAST);
	
	lr_start_transaction("Flight");
	
	//步骤1:选择航班出发地和目的地及座位属性
	web_submit_form("reservations.pl", 
		"Snapshot=t11.inf", 
		ITEMDATA, 
		"Name=depart", "Value=Denver", ENDITEM, 
		"Name=departDate", "Value=04/24/2021", ENDITEM, 
		"Name=arrive", "Value=London", ENDITEM, 
		"Name=returnDate", "Value=04/25/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=6", ENDITEM, 
		LAST);
	
	
	//步骤2:选择乘坐航班
	web_submit_form("reservations.pl_2", 
		"Snapshot=t12.inf", 
		ITEMDATA, 
		"Name=outboundFlight", "Value=020;338;04/24/2021", ENDITEM, 
		"Name=reserveFlights.x", "Value=36", ENDITEM, 
		"Name=reserveFlights.y", "Value=5", ENDITEM, 
		LAST);

	//步骤3:完成支付
	status=web_submit_form("reservations.pl_3", 
		"Snapshot=t13.inf", 
		ITEMDATA, 
		"Name=firstName", "Value=Jojo", ENDITEM, 
		"Name=lastName", "Value=Bean", ENDITEM, 
		"Name=address1", "Value=", ENDITEM, 
		"Name=address2", "Value=", ENDITEM, 
		"Name=pass1", "Value=Jojo Bean", ENDITEM, 
		"Name=creditCard", "Value=", ENDITEM, 
		"Name=expDate", "Value=", ENDITEM, 
		"Name=saveCC", "Value=<OFF>", ENDITEM, 
		"Name=buyFlights.x", "Value=47", ENDITEM, 
		"Name=buyFlights.y", "Value=9", ENDITEM, 
		LAST);
	
	
	 /* End transaction with operation result - pass or fail */
	if (status == 0)
	    lr_end_transaction("Flight", LR_PASS);
	else
	    lr_end_transaction("Flight", LR_FAIL);


	web_image("SignOff Button", 
		"Alt=SignOff Button", 
		"Ordinal=1", 
		"Snapshot=t14.inf", 
		LAST);

    
	return 0;
}

 

 2、lr_whoami

lr_whoami_Func()
{
	int id, scid;
	char *vuser_group;  //Memory for vuser_group is allocated automatically. Do not alter the string.
	lr_whoami(&id, &vuser_group, &scid);
	lr_message( "Group: %s, vuser id: %d, scenario id %d", vuser_group, id, scid);

	return 0;
}

Vugen日志输出:

 

 Controller日志输出:

 

 3、lr_get_host_name

lr_get_host_name_Func()
{
	char * my_host;
	my_host = lr_get_host_name( );
	lr_output_message("my_host :%s", my_host); 

	return 0;
}

Vugen日志输出:

Controller日志输出:

 4、lr_get_master_host_name

lr_get_master_host_name_Func()
{
	
	char * controller_host;
	controller_host = lr_get_master_host_name( );
	lr_output_message("controller_host :%s", controller_host); 

	return 0;
}

Vugen日志输出:可以看到打印的主机名称为None

 

Controller日志输出:可以看到成功打印主机名称

 

5、lr_get_vuser_ip

lr_get_vuser_ip_Func()
{
	char *ip;
	ip = lr_get_vuser_ip();
	if (ip)
	     lr_output_message("The IP address is %s", ip);
	else
	     lr_output_message("IP spoofing disabled");
     
	return 0;
}

 

待续......