事務(wù)函數(shù): lr_start_transaction();//標(biāo)記事務(wù)的開始 lr_start_transaction();/*標(biāo)記事務(wù)的結(jié)束,一般情況下,事務(wù)開始與結(jié)束聯(lián)合使用*/ lr_get_trans_instance_status();//得到事務(wù)的狀態(tài) lr_get_transaction_think_time();//得到事務(wù)的指定思考時間,事務(wù)時間=整體事務(wù)時間-事務(wù)的 lr_stop_transaction();//停止事務(wù) 日志函數(shù): lr_debug_message();//發(fā)送調(diào)試信息到日志文件 lr_error_message();//發(fā)送錯誤信息到LR輸入窗口或日志文件里 lr_get_debug_message();//返回當(dāng)前調(diào)試的信息 lr_log_message();//發(fā)送信息到用戶日志文件 lr_output_message();//發(fā)送信息到輸出窗口或日志文件 lr_vuser_status_message();//發(fā)送虛擬用戶的狀態(tài)到LR的Controller 運(yùn)行時函數(shù): lr_abort();//終止執(zhí)行的腳本 lr_continue_on_error();//當(dāng)發(fā)生錯誤后運(yùn)行的事件 lr_exit();//從scirpt.ation.iteration中退出 lr_rendezvous_ex();//設(shè)置集合點(diǎn) lr_think_time();//設(shè)置思考時間,在性能測試中為了更好模擬以后操作,可以根據(jù)實(shí)際生產(chǎn)環(huán)境設(shè)置思考時間。 lr_rendezous();//集合點(diǎn),可以設(shè)置虛擬用戶相同操作之前進(jìn)行集合,通過集合點(diǎn)可以增加被測試應(yīng)用的壓力,從而達(dá)到壓力測試的目的。 lr_load_dll();//調(diào)用DLL文件 例子: lr_load_dll("user32.dll"); MessageBoxA(NULL,"This is Testing Message","message_caption",0); return 0; 系統(tǒng)信息函數(shù): lr_get_master_host_name();//返回運(yùn)行Controller主機(jī)的名稱 lr_get_user_ip();//返回虛擬用戶的IP地址 lr_user_data_point();//錄制用戶自定義的數(shù)據(jù)樣例 lr_user_data_point();// 記錄自己的數(shù)據(jù)來進(jìn)行分析,每次要記錄一個點(diǎn)時,請使用該函數(shù)記錄采樣名稱和值。系統(tǒng)將自動記錄采樣的時間。執(zhí)行之后,可以使用用戶等義的數(shù)據(jù),點(diǎn)擊圖形分析結(jié)果 lr_get_host_name();//返回主機(jī)名 例子; char * host; host=lr_get_host_name(); lr_output_message("Computer Name %s",host); return 0; WEB應(yīng)用中常見函數(shù) web_url();//根據(jù)函數(shù)中的URL屬性加載對應(yīng)的URL,不需要上下文。 web_image();//模擬鼠標(biāo)在指定圖片上的單擊動作。此函數(shù)必須在有前置操作的上下文中使用。 Tips:在Toos—Recording Option,如果錄制級別設(shè)為基于HMTL的錄制方式時,web_image才會被錄制到。 Web_link();//模擬鼠標(biāo)在由若干個屬性集合描述的鏈接上進(jìn)行單擊。此函數(shù)必須在前置動作的上下文中才可以執(zhí)行。 web_submit_form ();//函數(shù)用來提交表單。此函數(shù)可能必須在前一個操作的上下文中執(zhí)行。 Tips:支持Web虛擬用戶,不支持WAP虛擬用戶。 web_submit_data();//函數(shù)處理無狀態(tài)或者上下文無關(guān)的表單提交。它用來生成表單的GET或POST請求,這些請求與Form自動生成的請求是一樣的。發(fā)送這些請求時不需要表單上下文。 web_find();//此函數(shù)的作用是在HTML頁面中查找指定的字符串。當(dāng)指定的HTML請求全部完成以后,開始執(zhí)行搜索過程,比web_reg_find要慢。 web_find函數(shù)在C語言的腳本中已經(jīng)被web_reg_find所替代,web_reg_find運(yùn)行速度比較快,而且在HTML-based和URL-based的錄制方式中都可以使用。 在C語言腳本中,web_find是向后兼容的。Java和Visual Basic腳本中不再支持它。 web_image_check();//檢查指定的圖象是否在HTML頁面中出現(xiàn),此函數(shù)僅僅支持基于HTML的腳本。 web_reg_add_cookie();//是注冊類型的函數(shù)。它首先注冊一個搜索文本字符串的請求。檢查動作在后續(xù)的Action函數(shù)之后進(jìn)行。如果字符串被找到,就添加到cookie中。 web_reg_find();//屬于注冊函數(shù),注冊一個在web頁面中搜索文本字符串的請求,在接下來的Action(象web_url)類函數(shù)中執(zhí)行搜索。 web_concurrent_start();//函數(shù)是并發(fā)組開始的標(biāo)記。組中所有的函數(shù)是并發(fā)執(zhí)行的。并發(fā)組的結(jié)束web_concurrent_end 函數(shù)。 web_reg_save_param();//關(guān)聯(lián)函數(shù),通過關(guān)聯(lián)可以在測試中保持動態(tài)值,從服務(wù)器返回的數(shù)據(jù)庫中查找需要關(guān)聯(lián)的數(shù)據(jù)。 web_add-filter();// 過濾函數(shù),用于對指定的URL進(jìn)行過濾,分析URL加載那部分對性能有影響。界面操作Run-time Settings 下的 Internet Protocol的Download Filters。 web_custom_request();// 自定義請求函數(shù),可以編寫自定義請求格式進(jìn)行接口功能測試。 FTP /IMAP方面: ftp_logon_ex();//針對特定會話登錄到FTP服務(wù)器。 ftp_put_ex();//在FTP服務(wù)器上設(shè)置工作目錄及上傳文件。 ftp_logout_ex();//注銷當(dāng)前FTP連接。 imap_create();//創(chuàng)建新的郵件。 imap_check();//郵件中請求檢查點(diǎn),實(shí)現(xiàn)并適用與郵箱內(nèi)部的內(nèi)務(wù)管理。 Tips:針對IMAP的測試,把函數(shù)中的ftp替換成imap即可。 其它常用函數(shù): Lr_decrypt():LR中的解密函數(shù) 實(shí)例代碼: lr_output_message("解密函數(shù)測試,解密后數(shù)值:%s",lr_decrypt("4e0942869c958e3e")); Getenv():得到定義的環(huán)境變量值 實(shí)例代碼: char *tmp,logfile[256],dlr_seperator; logfile; //Create an environment variable putenv("LOGFILE_NAME=lr_xiaolintest.txt"); // if(tmp = (char*)getenv("TEMP")) lr_output_message("Temp Dir = %s",tmp); else{ lr_output_message("TEMP environment variable undefined"); return -1; } sprintf(logfile,"%s\\%s",tmp,(char*)getenv("LOGFILE_NAME")); System():執(zhí)行操作系統(tǒng)的命令 char filename[1024],command[1024]; char new_dir[] = "c:\\test"; //Create a directory udder root called test and make it the current dir if(mkdir(new_dir)) lr_output_message("Create directory :%s failed",new_dir); else lr_output_message("Create new directory %s",new_dir); sprintf(filename,"%s\\%s",new_dir,"xialin.txt"); //Executr a dir /b command and directory it to a new_file sprintf(command,"dir /b c:\\ > %s /w",filename); system(command) lr_output_message("Create new file %s",filename); Rand():得到一個整型的隨機(jī)值(0到32767) srand(time(NULL)); //Generate a random number from 0-99 lr_output_message("A number between 0 and 99 is :%d\n",rand()%100); return 0; Getdrive()and mkdir():返回當(dāng)前驅(qū)動盤的名字。 int ch,drive,curdrive; static char path[1024]; //Save current drive letter so it can be restored later curdrive = getdrive(); //If we can switch to the drive,it exists lr_output_message("Available drives are:"); for(drive = 1;drive <= 26;drive++) if (!chdrive(drive)) lr_output_message("%c:",drive + 'A' -1); chdrive(curdrive);//Restore original drive return 0; Time():返回系統(tǒng)的時間 typedef long time_t; time_t t; //Get system time and display as number and string lr_message("Time in seconds since 1/1/88: %ld\n",time(&t)); lr_message("Formatted time and date: %s",ctime(&t)); return 0; |
|