1. 程式人生 > >LoadRunner例子:檢查點為參數的一個例子

LoadRunner例子:檢查點為參數的一個例子

out ssi end cti common 登陸 diff source star

LoadRunner例子:檢查點為參數的一個例子

檢查點是LoadRunner的一個功能,用來驗證業務功能的正確性。如果檢查的內容是變化的,腳本該如何寫呢?

問題提出:LoadRunner訂票網站例子中,創建一個虛擬用戶腳本,在登陸完成之後,設立一個檢查點,來檢查“welcome, xxx”。其中xxx為登陸的用戶名稱。

解決方法:

1)使用web_find() 做檢查點

Action()
{

//連接字符串,把welcome和用戶名組合成一個字符串

char teststring[1024]="Welcome, ";
strcat( teststring,lr_eval_string("{username}") );
lr_output_message("%s", teststring);
lr_save_string( teststring,"findtext" );

// [WCSPARAM WCSParam_Diff1 43 97279.0909680032fAADHQDpctVzzzzHDAAccpHfQtf]

//Parameter {WCSParam_Diff1} created by Correlation Studio

//關聯操作
web_reg_save_param("WCSParam_Diff1",
"LB=userSession value=",
"RB=>",
"Ord=1",
"RelFrameId=1.2.1",
"Search=Body",
"IgnoreRedirections=Yes",
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_think_time(11);

lr_start_transaction("test");


web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={WCSParam_Diff1}", ENDITEM,
"Name=username", "Value={username}", ENDITEM, //參數化用戶名
"Name=password", "Value=bean", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=42", ENDITEM,
"Name=login.y", "Value=13", ENDITEM,
LAST);

//檢查點

web_find("web_find",
"What={findtext}",
LAST);

lr_end_transaction("test", LR_AUTO);


return 0;
}

2)使用web_reg_find()做檢查點

Action()
{

//字符串操作,生成要檢查的字符串變量

char teststring[1024]="Welcome, <b>";
strcat( teststring,
lr_eval_string("{username}") );
lr_output_message("%s", teststring);
lr_save_string( teststring,"findtext" );

//關聯

// [WCSPARAM WCSParam_Diff1 43 97279.0909680032fAADHQDpctVzzzzHDAAccpHfQtf] Parameter {WCSParam_Diff1} created by Correlation Studio
web_reg_save_param("WCSParam_Diff1",
"LB=userSession value=",
"RB=>",
"Ord=1",
"RelFrameId=1.2.1",
"Search=Body",
"IgnoreRedirections=Yes",
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_think_time(11);

lr_start_transaction("test");

//檢查點
web_reg_find("Text={findtext}",
"Search=Body",
LAST);

web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={WCSParam_Diff1}", ENDITEM,
"Name=username", "Value={username}", ENDITEM, //參數化登陸名稱
"Name=password", "Value=bean", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=42", ENDITEM,
"Name=login.y", "Value=13", ENDITEM,
LAST);

lr_end_transaction("test", LR_AUTO);


return 0;
}

轉自:http://www.51testing.com/html/66/34866-73250.html

LoadRunner例子:檢查點為參數的一個例子