1. 程式人生 > >使用批處理自動執行Loadrunner指令碼

使用批處理自動執行Loadrunner指令碼

ET M_ROOT=D:\Mercury Interactive\Mercury LoadRunner\bin   cd %M_ROOT%   wlrun.exe -TestPath D:\ceshi10\ScenarioNo1.lrs -port 8080 -Run -DontClose   其中D:\Mercury Interactive\Mercury LoadRunner\bin 是安裝目錄   D:\ceshi10\ScenarioNo1.lrs是指令碼目錄   DontClose 指令碼執行完不關閉控制器,   以上是批處理   把批處理加到 windows的任務計劃裡,設定好執行時間,就可以了   This means the Controller can be started from a DOS batch (.bat) file (preferrably with a short name on a root drive):   REM Start Controller:   SET M_ROOT=C:\Program Files\Mercury Interactive\LoadRunner\bin   cd %M_ROOT%   wlrun.exe -TestPath D:\Dev\Dev1.lrs -port 8080 -Run -DontClose   pause Press Ctrl-Z to keep this window or   Including the -Run parameter is the same as manually pressing the "Start Scenario" automatically upon invocation. This is not a good idea because you may have to decide about collating the file from a previous run or want to change the output folder   Controller命令列執行引數
  【重點提示】   (1)如果在命令列中不使用引數呼叫Controller,則Controller將使用預設設定。   (2)Controller總是會覆蓋結果。   (3)場景終止時,Controller將自動終止,並收集結果。如果不希望Controller在場景終止時自動終止,可向命令列新增-DontClose標誌。   Ref http://bbs.51testing.com/thread-25171-1-1.html   我發現我們測試的時候總要設定不同的Vuser來測試,對比測試結果,我以前都是開啟Controller,設定5個Vuser然後跑,跑完後再改成10 個Vuser,再跑.....這樣不停的改使用者跑測試,一次一次總要看著,很浪費時間,所以就想找一個簡單的辦法讓Controller自己一個一個的跑 測試,併發測試結果放到不同的資料夾裡,晚上跑起這個程式,白天來了就可以拿結果了,經過向各位高人的
學習
,終於找到一個方法,那就是自己寫一個批處理文 件來執行測試。   方法並不難,是這樣的:(假設我們的操作都在D盤的TEST這個目錄下)   1. 先隨便錄製l一個LR指令碼,儲存為 D:\TEST\test01   2. 開啟 LR 的 Controller,載入 test01 指令碼,並設定測試場景,比如設定 Vuser 為 1,儲存場景為:D:\TEST\Scenario1.lrs   3. 開啟 LR 的 Controller,載入 test01 指令碼,並設定測試場景,比如設定 Vuser 為 2,儲存場景為:D:\TEST\Scenario2.lrs   現在 D 盤的 TEST 目錄下有三個檔案了,一個是我們的指令碼 test01,其他兩個是測試場景 Scenario1.lrs和Scenario2.lrs   為了能讓這兩個場景自動執行,並把他們執行的結果分別儲存在不同的目錄裡,我們可以這樣:   在 D 盤的 TEST 目錄下建立一個文字檔案 RunTest.txt, 開啟它把下面一段貼進去:   PATH=C:\Program Files\Mercury Interactive\Mercury LoadRunner\bin\   wlrun -TestPath D:\TEST\Scenario1.lrs -Run -ResultName D:\TEST\res1   wlrun -TestPath D:\TEST\Scenario2.lrs -Run -ResultName D:\TEST\res2   儲存並關閉 RunTest.txt 檔案   上面第一句是設定路徑,即 LR Controller 的安裝路徑,一般在 Mercury Interactive\Mercury LoadRunner\bin\ 裡面,wlrun.exe 就是 Controller   然後第二句wlrun -TestPath D:\TEST\Scenario1.lrs -Run -ResultName D:\TEST\res1   是說 執行wlrun,啟動Scenario1.lrs這個場景,-Run是說執行Controller當執行結束後關閉Controller   -ResultName D:\TEST\res1 是說把測試結果儲存在 D:\TEST\res1 裡   好,現在把這個文字檔案 RunTest.txt 更名為 RunTest.bat, 雙擊就可以運行了,看看 Controller 是不是自己跑起來了