在QTP Test中利用vbs和cmd實現重新啟動QTP
連續長時間執行過QTP或使用QC連續長時間調用QTP的朋友應該會知道,QTP在長時間執行過程中會產生內存泄露。而QTP自身也有一個工具Remote Agent來實現每執行N次來重新啟動測試工具釋放內存。
但是,不知道是不是我用破解版的原因,如果使用RunTest來調用QC執行QTP時,這個設置的Remote Agent會使得測試失敗,并卡死在某一步。所以在這里需要進行手動清理QTP長時間運行過程中產生的內存泄露。
在這里,我所知的清理內存有兩種方式,一種是利用一些內存清理工具,一種是通過腳本控制QTP重新啟動。
首先說說內存清理工具。今天在群里下到了一個兄弟共享的內存清理工具memempty.exe,它可以進行定時清理。但是由于QTP執行每個Test的時間都不相同,并且QTP在執行過程中,這個工具也無法有效的清理干凈內存部分。對這些不是很懂,點下就行了,免得出丑。
使用腳本控制,這里我用的是創建外部vbs并通過cmd命令來執行的方式實現的,腳本如下:
dim restartcode set?fso?=?CreateObject("Scripting.FileSystemObject") set?file?=?fso.CreateTextFile("D:\RestartQTP.vbs") restartcode?=?"'浣跨敤涓€涓瓑寰呮椂闂翠嬌寰梣tp鑳借繑鍥瀜c涓€涓墽琛屾垚鍔熺殑緇撴灉"&vbnewline restartcode?=?restartcode?&"WScript.Sleep?3000"&vbnewline restartcode?=?restartcode?&"'浣跨敤AOM鏉ユ帶鍒秖tp鐨勯噸鍚搷浣?"&vbnewline restartcode?=?restartcode?&"Dim?qtp"&vbnewline restartcode?=?restartcode?&"Set?qtp?=?CreateObject(""QuickTest.Application"")"&vbnewline restartcode?=?restartcode?&"qtp.Quit"&vbnewline restartcode?=?restartcode?&"WScript.sleep?2000"&vbnewline restartcode?=?restartcode?&"qtp.Launch"&vbnewline restartcode?=?restartcode?&"qtp.visible?=?true"&vbnewline restartcode?=?restartcode?&"set?qtp?=?nothing"&vbnewline restartcode?=?restartcode?&"set?fso?=?CreateObject(""Scripting.FileSystemObject"")"&vbnewline restartcode?=?restartcode?&"fso.deletefile?""D:\RestartQTP.vbs"""&vbnewline restartcode?=?restartcode?&"set?fso?=?nothing"&vbnewline file.write?restartcode set?fso?=?nothing set?WshShell?=?CreateObject("WScript.Shell") WshShell.run?"cmd.exe?/c?D:\RestartQTP.vbs" set?WshShell?=?nothing? |
這樣就可以實現重新啟動QTP了,不過在執行下一個test之前需要一個等待時間,這個在調用腳本中很簡單,就不羅嗦了
posted on 2013-12-24 11:40 順其自然EVO 閱讀(311) 評論(0) 編輯 收藏 所屬分類: qtp