loadRunner寫腳本實現登錄機票網站,手動關聯,獲取頁面源碼中特定字符
手動關聯,就是通過函數獲取某個步驟生成的字符,賦值給一個變量,這個變量可以作為接下來某個步驟的輸入,
以便這個腳本能夠在存在關聯約束關系的場景中順利走通,例如登錄機票預訂系統步驟的條件之一,是需要在進入首頁時獲取一個動態的usersession的值,
這個userSession的值需要在登錄系統時用到,那么在通過關聯函數可以在進入主業時動網頁源代碼中獲取這個值,然后在登錄時把這個值傳給參數就可以了
代碼:
Action()
{
//<B>sign up now</B></A>
web_reg_save_param_regexp(
"ParamName=gloryroad",
"RegExp=<B>(.*)</B></A>",
SEARCH_FILTERS,
"Scope=Body",
"IgnoreRedirections=No",
LAST);
web_url("index.htm",
"URL=http://127.0.0.1:1080/WebTours/index.htm",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t20.inf",
"Mode=HTML",
LAST);
return 0;
}
結果:匹配成功
手動關聯的另一個例子:進入首頁后 ,獲取userSession,在登錄機票系統傳入這個變量
代碼:
Action()
{
/*Correlation comment - Do not change! Original value='125352.422519239zttHiVfpcDDDDDDDDizizpiQVt' Name ='userSession' Type ='ResponseBased'*/
web_reg_save_param_regexp(
"ParamName=userSession",
"RegExp=name=\"userSession\"\\ value=\"(.*?)\"/>\\\n<table\\ border",
SEARCH_FILTERS,
"Scope=Body",
"IgnoreRedirections=No",
"RequestUrl=*/nav.pl*",
LAST);
web_url("index.htm",
"URL=http://127.0.0.1:1080/WebTours/index.htm",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t20.inf",
"Mode=HTML",
LAST);
lr_save_string(lr_decrypt("5c3c9ad6232a1458"), "PasswordParameter");
lr_think_time(6);
//斷言登錄后的字符串
web_reg_find("Text=Using the menu to the left",
LAST );
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/cgi-bin/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?in=home",
"Snapshot=t21.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={userSession}", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=43", ENDITEM,
"Name=login.y", "Value=6", ENDITEM,
"Name=password", "Value=xfc1", ENDITEM,
//"Name=userSession", "Value= 125352.083920616zttHHQHpiVzzzzzHDizizpHizQ", ENDITEM,
"Name=username", "Value=xfc1", ENDITEM,
LAST);
return 0;
}
結果: