1. 程式人生 > >loadrunner:文字檢查點web_reg_find和web_find兩個函式的區別

loadrunner:文字檢查點web_reg_find和web_find兩個函式的區別

web_reg_find是先註冊(register)後查詢的;使用時將它放在請求語句的前面。
而web_find是查詢前面的請求結果;使用時將它放在請求語句的後面。

另二者的引數也完成不一樣的,web_reg_find引數中SaveCount記錄查詢匹配的次數,
web_find的機制是一旦查詢匹配成功就立即返回,並不繼續查詢和記錄匹配次數

再者Run-time設定中的“enable image and textcheck”對web_find有效,而對web_reg_find無效。
注意:web_find不支援URL模式下錄製的指令碼。

執行效率:
web_reg_find可以直接在記憶體裡面檢查所指定物件是否存在;而web_find是文字檢查點,需要對應頁面完全顯示出來之後,才會執行檢查。概言之,使用web_reg_find不用啟用文字檢查點功能;使用web_find就一定要啟用文字檢查點功能,否則檢查點無效。

很顯然,前者比後者執行效率要高,這也是LR要不建議使用後者的原因。

而web_reg_find()就不能通過它的返回值來作為事務的判斷條件,因為web_reg_find()的返回值0和1表示web_reg_find()是否註冊成功(web_reg_find是註冊型別函式,它本身並不執行),並不代表查詢的內容是否存在,也就是說無論查詢的文字內容是否存在,都返回0,(和web_find的返回值意義就不同了)。

我想問的是有什麼方法用web_reg_find()來作為事務的判斷條件?
利用web_reg_find建立的引數SaveCount ,作為判斷條件就可以了(如SaveCount>0)

web_find()(幫助不太推薦使用web_find而是推薦使用web_reg_find)要寫在請求後,也就是要在事務內了。這樣通過事務統計出來的響應時間就(包括了web_find()這個函式的執行時間)不真實了。而web_reg_find()是寫在請求前面的。如果能用web_reg_find()來作為事務結束條件,那就是最好的.
事務時間等於Duration-Wasted Time,web_reg_find執行的時間Loadrunner會自動減掉的

另,LR自身已經提供了關於Page title的檢查點的設定。路徑: Recording setting >Advanced.

指令碼示例:

同樣的script, 如果新增web_reg_find,事務執行結果失敗:

Action.c(50): Error -26366:"Text=Dashboard" not found for web_reg_find        [MsgId:MERR-26366]

Action.c(50):web_submit_form("wp-login.php_2") highest severity level was"ERROR", 39882 body bytes, 3207 header bytes, 12 chunking overheadbytes        [MsgId:MMSG-26387]

Action.c(50): Notify: Transaction"Login_WordPress" ended with "Fail" status (Duration: 5.9267 WastedTime: 0.0000).

Ending action Action.

Endingiteration 2. 而如果沒有同,整個事務,包括 action執行成功:

Action.c(110):web_url("index-extra.php_5") was successful, 1047 body bytes, 2682header bytes, 12 chunking overhead bytes        [MsgId:MMSG-26385]

Action.c(124): Log onsuccessfully

Ending action Action.

Ending iteration 2.

Action() { int status; //定義變數,用於判斷登陸是否成功 //   web_add_cookie("rtime=1;DOMAIN=bjdns2.cncmax.cn"); // // web_add_cookie("ltime=1303876351121;DOMAIN=bjdns2.cncmax.cn"); // //web_add_cookie("cnzz_eid=64563578-1302487037-http://bjdns2.cncmax.cn:8080/?HOST=home.beyondsoft.com&R=/&DOMAIN=bjdns2.cncmax.cn"); // //web_add_cookie("JSESSIONID=E73D3BF7B18442F72B93F5EF37B5E545;DOMAIN=bjdns2.cncmax.cn"); web_url("bjdns2.cncmax.cn:8080", "URL=http://bjdns2.cncmax.cn:8080/?HOST=wpad.beyondsoft.com&R=/wpad.dat&", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST); // web_add_cookie("wp-settings-time-1=1304042778;DOMAIN=demo.opensourcecms.com"); // // web_add_cookie("wordpress_test_cookie=WP+Cookie+check;DOMAIN=demo.opensourcecms.com"); // //web_add_cookie("wordpress_logged_in_613541581fd3dd54ee5153849996d0f6=admin|1304215578|8148fb498981bf15c2f239b9d3dbdf5d;DOMAIN=demo.opensourcecms.com"); // //web_add_cookie("wordpress_613541581fd3dd54ee5153849996d0f6=admin|1304215578|616ad0d48cfd28158b012254e00fe732;DOMAIN=demo.opensourcecms.com"); // web_url("wp-login.php", "URL=http://demo.opensourcecms.com/wordpress/wp-login.php", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t2.inf", "Mode=HTML", EXTRARES, "URL=wp-admin/images/button-grad.png", ENDITEM, "URL=wp-admin/images/white-grad.png", ENDITEM, "URL=wp-admin/images/logo-login.gif", ENDITEM, LAST); lr_start_transaction("Login_WordPress"); //注意,該函式應該插入到提交時會出現該欄位的地方之前。  //web_reg_find("Text=Dashboard",   //"Search=Body",   //LAST); web_submit_form("wp-login.php_2", "Snapshot=t3.inf", ITEMDATA, "Name=log", "Value={UserName}", ENDITEM, "Name=pwd", "Value={Password}", ENDITEM, "Name=rememberme","Value=<OFF>", ENDITEM, "Name=wp-submit", "Value=Log In", ENDITEM, EXTRARES, "URL=wp-admin/images/wp-logo.png?ver=20100531","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/fav-arrow.gif?ver=20100531","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/menu.png?ver=20100531","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/menu-bits.gif?ver=20100610","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/menu-dark.gif","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/menu-arrows.gif","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/screen-options-toggle.gif?ver=20100531","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/icons32.png?ver=20100531","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/gray-grad.png","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-includes/js/thickbox/loadingAnimation.gif","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, "URL=wp-admin/images/fade-butt.png","Referer=http://demo.opensourcecms.com/wordpress/wp-admin/",ENDITEM, LAST); lr_end_transaction("Login_WordPress", LR_AUTO); web_url("index-extra.php", "URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_incoming_links", "Resource=0", "RecContentType=text/html", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", "Snapshot=t4.inf", "Mode=HTML", LAST); web_url("index-extra.php_2", "URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_primary", "Resource=0", "RecContentType=text/html", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", "Snapshot=t5.inf", "Mode=HTML", LAST); web_url("index-extra.php_3", "URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_secondary", "Resource=0", "RecContentType=text/html", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", "Snapshot=t6.inf", "Mode=HTML", LAST); web_url("index-extra.php_4", "URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_plugins", "Resource=0", "RecContentType=text/html", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", "Snapshot=t7.inf", "Mode=HTML", LAST); web_url("index-extra.php_5", "URL=http://demo.opensourcecms.com/wordpress/wp-admin/index-extra.php?jax=dashboard_quick_press", "Resource=0", "RecContentType=text/html", "Referer=http://demo.opensourcecms.com/wordpress/wp-admin/", "Snapshot=t8.inf", "Mode=HTML", LAST); if(status == LR_FAIL) { lr_error_message("Log onfailed"); return -1; } else{ lr_output_message("Log onsuccessfully"); return 0; } }