LoadRunner中web_reg_find的SaveCount變量一直爲0解決辦法

最近把以前學習過的LoadRunner翻出來又從新學習了一下,過程當中出現web_reg_find的SaveCount計數一直爲0的現象。前期腳本以下:html

Login()
{

	web_reg_save_param("Session",
					   "LB=name=userSession value=",
					   "RB=>",
					   LAST);

	web_reg_find("Text=Web Tours reservation pages",
			 "SaveCount=nameCount",
			 "Search=Body",
			 LAST);

	web_url("WebTours", 
		"URL=http://127.0.0.1:1080/WebTours/", 
		"TargetFrame=", 
		"Resource=0", 
		"RecContentType=text/html", 
		"Referer=", 
		"Snapshot=t1.inf", 
		"Mode=HTML", 
		LAST);

	lr_start_transaction("Login");

	web_submit_data("login.pl", 
		"Action=http://127.0.0.1:1080/WebTours/login.pl", 
		"Method=POST", 
		"TargetFrame=", 
		"RecContentType=text/html", 
		"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 
		"Snapshot=t2.inf", 
		"Mode=HTML", 
		ITEMDATA, 
		"Name=userSession", "Value={Session}", ENDITEM, 
		"Name=username", "Value=test1", ENDITEM, 
		"Name=password", "Value=111111", ENDITEM, 
		"Name=JSFormSubmit", "Value=on", ENDITEM, 
		"Name=login.x", "Value=62", ENDITEM, 
		"Name=login.y", "Value=10", ENDITEM, 
		LAST);

	lr_end_transaction("Login",LR_AUTO);

	lr_output_message("username count is %s",lr_eval_string("{nameCount}"));

	return 0;
}

輸出的結果老是顯示「Login.c(45): username count is 0」,後來想起web_reg_find函數要放在請求發送前面,而後就修改了一下web_reg_find的位置:web

Login()
{

	web_reg_save_param("Session",
					   "LB=name=userSession value=",
					   "RB=>",
					   LAST);

	web_url("WebTours", 
		"URL=http://127.0.0.1:1080/WebTours/", 
		"TargetFrame=", 
		"Resource=0", 
		"RecContentType=text/html", 
		"Referer=", 
		"Snapshot=t1.inf", 
		"Mode=HTML", 
		LAST);

	lr_start_transaction("Login");

	web_reg_find("Text=Web Tours reservation pages",
			 "SaveCount=nameCount",
			 "Search=Body",
			 LAST);

	web_submit_data("login.pl", 
		"Action=http://127.0.0.1:1080/WebTours/login.pl", 
		"Method=POST", 
		"TargetFrame=", 
		"RecContentType=text/html", 
		"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 
		"Snapshot=t2.inf", 
		"Mode=HTML", 
		ITEMDATA, 
		"Name=userSession", "Value={Session}", ENDITEM, 
		"Name=username", "Value=test1", ENDITEM, 
		"Name=password", "Value=111111", ENDITEM, 
		"Name=JSFormSubmit", "Value=on", ENDITEM, 
		"Name=login.x", "Value=62", ENDITEM, 
		"Name=login.y", "Value=10", ENDITEM, 
		LAST);

	lr_end_transaction("Login",LR_AUTO);

	lr_output_message("username count is %s",lr_eval_string("{nameCount}"));

	return 0;
}

再次執行,顯示結果符合預期。特別再次記錄下。按書中所說,web_reg_find必定要放在實際請求提交以前,中間不能隔着其餘東西。函數

相關文章
相關標籤/搜索