LoadRunner小技巧集锦
?
?
1、錄制腳本中包含中文,出現亂碼怎么辦?
把錄制選項中的Support charset選中UTF-8
?
?
錄制腳本后,切換到樹視圖中,打開相應的腳本頁面。在右側的PageView中錄制的腳本呈現中文版式,但是當切換到Server Response中,所有的中文全部換成的亂碼,如“勌缞仫訆”。
?
原因是服務器端沒有把響應的編碼設置為gb2312
?
在IIS中找到Web.Config文件,在<system.web>….</system.web>節加 入<globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312"/>后再次錄制腳本,亂碼變中文。
?
2、錄制到的腳本是空白的
有可能是由于錄制的URL地址采用的是localhost的問題,改成分配的IP地址或127.0.0.1試試。
?
?
3、插入文本檢查點步驟時,使用web_reg_find,通常TextPfx和TextSfx中會包含雙引號,需要進行轉義(用斜杠),例如:
?
?????? web_reg_find("Search=Body",
????????????? "SaveCount=Welcome",
????????????? "TextPfx=歡迎<a class=\"drop\" id=\"viewpro\" onMouseOver=\"showMenu(this.id)\">",
????????????? "TextSfx=</a>",
????????????? LAST);
?
4、使用web_image_check插入圖片檢查點時需要主要設置Run-Time Setting中的Enable Image and text check選項:
?
?
使用web_find函數插入文本檢查點也一樣要做此設置
?
5、性能測試往往需要準備大批量的數據,大批量數據的生成方法有很多種,常見的有:
?????? (1)編寫SQL語句來插入數據
(2)使用DataFactory等專業的數據生成工具
?????? (3)通過LoadRunner錄制回放的方式重復執行生成大批量數據
?
Tips:
使用DataFactory插入nchar數據類型的數據時會出現空值的情況,可以先修改數據庫的數據類型設置,插完數據后再改回來
?
6、在錄制腳本的過程中插入注釋,錄制后查看和理解腳本會更加方便。
?
?
7、LoadRunner回放腳本時,在瀏覽器顯示的中文是亂碼
?
解決辦法(1):
首先設置Run-Time Settings – Browser – Browser Emulation – User-Agent
?
?
然后設置IE:
查看-編碼-鉤上“自動選擇”和Unicode(UTF-8)。
?
解決辦法(2):
使用lr_convert_string_encoding函數來轉換編碼
?
下面是一個使用的例子:
lr_convert_string_encoding(lr_eval_string("{ReplyContents}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"ReplyMessage");
?
?????? web_submit_data("postreply.aspx_2",
????????????? "Action=http://127.0.0.1/postreply.aspx?infloat=1&topicid=2&&inajax=1",
????????????? "Method=POST",
????????????? "EncType=multipart/form-data",
????????????? "RecContentType=text/xml",
????????????? "Referer=http://127.0.0.1/showtopic-2.aspx",
????????????? "Snapshot=t9.inf",
????????????? "Mode=HTML",
????????????? ITEMDATA,
????????????? "Name=iconid", "Value=0", ENDITEM,
????????????? "Name=title", "Value=", ENDITEM,
????????????? "Name=wysiwyg", "Value=0", ENDITEM,
????????????? "Name=checkbox", "Value=0", ENDITEM,
????????????? "Name=message", "Value=[localimg=180,112]1[/localimg]\r\n\r\n{ReplyMessage}", ENDITEM,
????????????? "Name=e_mediatyperadio", "Value=on", ENDITEM,
????????????? "Name=sl_attachdesc", "Value=", ENDITEM,
????????????? "Name=attachid", "Value=", ENDITEM,
????????????? "Name=attachdesc", "Value=", ENDITEM,
????????????? "Name=localid", "Value=", ENDITEM,
????????????? "Name=attachdesc", "Value=", ENDITEM,
????????????? "Name=localid", "Value=1", ENDITEM,
????????????? "Name=attachdesc", "Value=", ENDITEM,
????????????? "Name=localid", "Value=2", ENDITEM,
????????????? "Name=emailnotify", "Value=on", ENDITEM,
????????????? "Name=postreplynotice", "Value=on", ENDITEM,
????????????? "Name=postfile", "Value=", "File=Yes", ENDITEM,
????????????? "Name=postfile", "Value=D:\\\\圖片收集\\\\It's about time.JPG", "File=Yes", ENDITEM,
????????????? "Name=postfile", "Value=", "File=Yes", ENDITEM,
????????????? "Name=uploadallowmax", "Value=10", ENDITEM,
????????????? "Name=uploadallowtype", "Value=jpg,gif", ENDITEM,
????????????? "Name=thumbwidth", "Value=300", ENDITEM,
????????????? "Name=thumbheight", "Value=250", ENDITEM,
????????????? "Name=noinsert", "Value=0", ENDITEM,
????????????? LAST);
?
8、可以在LR測試腳本的目錄中找到參數文件,直接修改參數文件
The parameter file is stored in the script directory as .dat file extension.? It can be opened with a simple text editor like Notepad as it is stored in pure text format.? Therefore, you can manipulate the files via the Notepad.? You can also use office applications such as Microsoft Excel or OpenOffice.org Calc to work on the file.? This greatly the amount of work required for maintaining a long list of data.
?
9、LR9.x啟動VUGen時提示"Failed to connect to server"
After upgrading to LoadRunner 9.x I started getting a window popup which said "Failed to connect to server" every time I opened virtual user generator (vugen.exe).
?
?
The solution to this was to close virtual user generator and delete the [vugen.ini] file.
vugen.ini is found in the %systemroot% folder on your Windows PC (usually C:\WINDOWS or C:\WINNT).
?
Once you've deleted the file, virtual user generator will open without any issues and create a new vugen.ini file automatically.
?
?
?
10、怎樣抓取有相同左右邊界的動態value?
怎樣抓取有相同左右邊界的動態value?例如:
stateID="d7lg0ehmjkkm6uin3s4boei7oq">
stateID="cvopakp46ftsf8mh6l37ti3ubm">
stateID="bv9mja8gtgr39ddibm5t9163re">
web_reg_save_param里的ORD應該怎樣設置?
?
?
?
?
ORD: Indicates the ordinal position or instance of the match. The default instance is 1. If you specify "All," it saves the parameter values in an array.
?
例子:
char outFlightParam[50]; // The name of the parameter for correlation
char outFlightParamVal[50]; // The formatted value of outFlightParam
web_reg_save_param("outFlightVal",
??????? "LB=outboundFlight value=", "RB=>",
??????? "ORD=ALL",
??????? "SaveLen=18",
??????? LAST);
?
??? web_submit_form("reservations.pl",
??????? "Snapshot=t4.inf",
??????? ITEMDATA,
??????? "Name=depart", "Value=London", ENDITEM,
??????? "Name=departDate", "Value=11/20/2003", ENDITEM,
??????? "Name=arrive", "Value=New York", ENDITEM,
??????? "Name=returnDate", "Value=11/21/2003", ENDITEM,
??????? "Name=numPassengers", "Value=1", ENDITEM,
??????? "Name=roundtrip", "Value=<OFF>", ENDITEM,
??????? "Name=seatPref", "Value=None", ENDITEM,
??????? "Name=seatType", "Value=Coach", ENDITEM,
??????? "Name=findFlights.x", "Value=83", ENDITEM,
??????? "Name=findFlights.y", "Value=16", ENDITEM,
??????? LAST);
?
??? sprintf(outFlightParam, "{outFlightVal_%s}",
??????? lr_eval_string("{outFlightVal_count}"));
??? sprintf(outFlightParamVal, "Value=%s",
??????? lr_eval_string(outFlightParam));
??? lr_message("The value argument is : %s", outFlightParamVal);
?
??? web_submit_form("reservations.pl_2",
??????? "Snapshot=t5.inf",
??????? ITEMDATA,
??????? "Name=outboundFlight",outFlightParamVal, ENDITEM,
??????? "Name=reserveFlights.x", "Value=92", ENDITEM,
??????? "Name=reserveFlights.y", "Value=10", ENDITEM,
??????? LAST);
?
?
?
11、運行場景時提示“Step download timeout (120 seconds) has expired when downloading resource(s)”
?
vuser_init.c(12): Error -27728: Step download timeout (120 seconds) has expired when downloading non-resource(s)(出現個別,可以忽略)
vuser_init.c(12): Error -27727: Step download timeout (120 seconds) has expired when downloading resource(s). Set the "Step Timeout caused by resources is a warning" Run-Time Setting to Yes/No to have this message as a warning/error, respectively
?
?
如果覺得下載一個頁面超過2分鐘不是錯誤的話,可以在Run-Time設置中選擇Preferences->Options,修改Step download timeout(sec)的時間
或者把“Step timeout caused by resources is a warning”設置為Yes,這樣下載資源超時也只是作為警告,不作為錯誤提示,但是對于非資源的下載超時,則總是會提示錯誤的
?
12、用strtok函數分割字符串
需要在loadrunner里面獲得“15”(下面紅色高亮的部分),并做成關聯參數。
//Body response 內容: <BODY><; PRE>//OK[8,7,5,15,6,5,0,4,0,3,0,3,2,0,0,0,1
?
用web_reg_save_param取出“8,7,5,15,6,5,0,4,0,3,0,3,2,0,0,0,1”這一段,然后用strtok函數切割出一個個數字,第四個數字就是要找的值
?
例如:
extern char * strtok(char * string, const char * delimiters ); // Explicit declaration
char separators[] = ",";
char * token;
lr_save_string("1,2,3,4,5,6","str");
token = (char *)strtok(lr_eval_string("{str}"), separators); // Get the first token
if (!token) {
??????? lr_output_message ("No tokens found in string!");
??????? return( -1 );
??? }
while (token != NULL ) { // While valid tokens are returned
??????? lr_output_message ("%s", token );
??????? token = (char *)strtok(NULL, separators); // Get the next token
??? }
?
?
?
?
13、LoadRunner沒有購買webservice協議的license,只有http的,可不可以完全用http協議模擬webservice?
?
可以,參考:
http://blog.testsautomation.com/2009/01/web-services-performance-using-loadrunner/
http://blog.testsautomation.com/2009/05/validating-web-service-response-with-xpath/
?
?
?
?
14、在場景設置中不忽略思考時間,但是在查看響應時間的時候怎樣讓LR自動在響應時間里減去思考時間?
?
在analysis中找到了設置是否在報告中包含思考時間的地方做相應的設置即可:
?
?
?
?
?
15、LoadRunner在運行過程中停掉1半虛擬用戶
?
Another issue that I’m facing from time to time is that LoadRunner stops 50% of running users without any notification, issue, error message etc. I’ve find out that it happens only when running with log level set to ‘always send a message’. Because of that, I suggest to run with log level set to ‘Send message only when error occur’.
?
?
?
16、LoadRunner錄制不了任何東西
?
Sometimes LoadRunner is not recording anything while browsing using IE. I have no idea why but the fastest solution is to restart whole LR. Maybe some of you have good explanation for that?
?
?
?
?
17、測試RTMP協議應該在LoadRunner選擇什么協議來錄制?
?
用flex協議
?
有這幾個函數可用:
flex_rtmp_connect? Connects a client to an RTMP server and sets connection options.?
flex_rtmp_disconnect? Disconnects a client from an RTMP server.?
flex_rtmp_send? Sends messages to an RTMP server.?
flex_rtmp_receive? Receives responses from an RTMP server
?
Flex can record and replay scripts involving RTMP (Real Time Messaging Protocol). In order to enable RTMP simulation, you must configure the recording options for the Flex protocol.
To enable RTMP:
1 Open the Recording Options dialog box by selecting Tools > Recording Options or clicking the Options button in the Start Recording dialog box.
2 In the Network > Port Mapping node click Options.
3 Set the Send-Receive buffer size threshold to 1500.
?
?
?
18、如何在LoadRunner中運行QTP腳本?
1、運行準備:
1)勾選QTP的Tools--Options--Run的"Alow other Mercury products to run tests and components"
2)錄制需要在lr中運行的QTP腳本,并且在QTP腳本中設置事務,Services.StartTransaction "start"與Services.EndTransaction "start"
2、運行QTP腳本
在LR中運行時選擇QTP腳本,為QTP腳本存放目錄下文件擴展名為.usr的文件。
注:LR中運行QTP腳本時,只能有一個Vuser,否則將報錯:
The load generator is currently running the maximum number of Vusers of this type
?
?
?
?
19、在LR中如何忽略Socket接收數據的驗證
在LR中對Socket進行性能測試時,LR會自己判斷lrs_receive回來的數據的長度,而如果長度不符的話會有時間延遲的情況(這是性能測試完全不能接受的事情),如果做到這一點呢,經過反復嘗試,發現一種簡單的方法(用*代替具體的長度):
?
類似于將:
recv buf1 12
"Hello, Denny"
?
改為:
recv buf1 *
"Hello, Denny"
?
一切OK。
?
?
?
20、LoadRunner9.5的Controller中不能添加Apache的監控
?
?
在C:\Program Files\HP\LoadRunner\dat\online_graphs中找到online_resource_graphs.rmd文件,修改[Apache]部分中的EnableInUI為1
參考:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1274450165814+28353475&threadId=1229523
?
?
21、VB Vuser開發ADO腳本,提示“user-defined type not defined”
想在VB Vuser寫入模擬數據操作的過程,然后在VB Vuser里定義了這個全局變量
Private m_Conn As ADODB.Connection '連接對象
Private m_Reco As ADODB.Recordset? '結果集
但是在VB Vuser中不識別這個對象,報出user-defined type not defined
?
?
需要在Run-Time 設置中的VBA部分把ADO的庫選上
如果用VB Script虛擬用戶來開發就不要,直接用CreateObject來創建ADO對象即可
?
?
22、loadrunner9.5錄制腳本時出現c:\PROGRA~1\MICROS~1\office12\Grooveutil.DLL時出錯內存位置訪問無效
?
Office2007的問題,IE加載項禁用Groove? GFSBrowser Helper 組件
?
?
23、LR自帶的例子端口號怎么修改?
LR自帶的例子端口號是1080,我怎么樣把這個端口設置我自己想用的端口號8088,在什么地方設置
?
?
在LR安裝目錄下,找到Xitami.config文件,找到portbase,可以修改它(默認是1000);
默認的端口號是portbase+80;
要把端口號改成8088,就把portionbase改為8008,保存之后就是了(8088=8008+80)。
?
24、用Web_reg_find查找中文字符串時查找不到
?
腳本文件里有個default.cfg ,里面有個參數是 UTF8InputOutput ,將其值改為0
?
?
?
25、替代IP Wizard的腳本
?
http://hi.baidu.com/higkoo/blog/item/39bbb21bc33d76dcac6e751c.html
?
LoadRunner自帶的“IP Wizard”用起來非常麻煩,要不停的點,重要的是最后還必須重啟系統生效。
于是乎寫個腳本替代之:
1. 假設客戶端IP為 192.168.10.31
2. 假設服務端IP為 192.168.10.10
3. 需要模擬的IP為 110.119.120.122
?
那么,客戶端提供添加虛擬IP的BAT腳本:
netsh??? interface??? ip??? add??? address??? 本地連接??? 110.119.120.122??? 255.255.0.0
對應的刪除設置為:
netsh??? interface??? ip??? del??? address??? 本地連接??? 110.119.120.122
?
對應服務器添加虛擬路由的Shell腳本:
route add -host 110.119.120.122 gw 192.168.10.31
刪除路由的腳本:
route del -host 110.119.120.122 gw 192.168.10.31
?
這樣就非常方便了,不用重啟任何機器,執行腳本就生效,再執行腳本就取消。
?
?
26、如何從命令行調用LoadRunner腳本?
?
Here is the command line that you need to execute to run a VuGen script from the command prompt:
???<LoadRunner>\bin\mmdrv.exe -usr <path to usr file>?
Note:
In order to get all the other options that go with the command, run mmdrv.exe from the command prompt without any options.
?
?
27、請問"int64這個類型,在LR中怎么表示"。我將一段C的代碼放在LR中,LR不認int64這個類型,怎么解決?
?
把那段C代碼做成DLL,然后在LR中調用
?
?
28、LoadRunner監控遠程機器Windows資源,提示“net use failed”
?
解決辦法:
在被監控機器上更改本地帳戶的共享和安全模式為經典模式。控制面板->管理工具->本地安全策略->網絡訪問:本地帳戶的共享和安全模式->經典模式。
?
監視連接前的準備工作:
首先保證被監視的windows系統開啟以下二個服務Remote Procedure Call(RPC) 和Remote Registry Service
被監視的WINDOWS機器:右擊我的電腦,選擇管理->共享文件夾->共享 在這里面要有C$這個共享文件夾,(要是沒有自己手動加)
然后保證在安裝LR的機器上使用運行.輸入\\被監視機器IP\C$ 然后輸入管理員帳號和密碼,如果能看到被監視機器的C盤了,就說明你得到了那臺機器的管理員權限,可以使用LR去連接了
?
?
?
?
?
?
?
?
?
?
?
?
? ----------- 軟件性能測試工作室:提供性能測試咨詢、培訓和項目指導 (QQ: 2225045276 E-Mail: Automa總結
以上是生活随笔為你收集整理的LoadRunner小技巧集锦的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .net中关键字new的用法
- 下一篇: 在Windows 下使用CodeBloc