Let's Go!

用VBS实现Loadrunner多场景的执行

上一篇 / 下一篇  2009-05-20 23:35:31 / 个人分类:LoadRunner


一、Loadrunner Controller 定时执行一个场景:

Scenario--->Start time--->at (time)------>千万不要忘了点击“Start Scenario”,否则定时不起作用
---->会弹出执行场景倒计时窗口


二、使用命令行!,比如说你先把场景设置好!然后你保存场景。然后再windows做一个定时器,写如下命令:
wlrun -TestPath 路径\场景文件 -Run
注意:wlrun这个可执行文件在LR的bin目录下!

     (开始----->程序---->附件---->系统工具----->任务计划)

三、'用VBS实现Loadrunner多场景的执行


Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /C c:\\db.lrs",1,true
'指定位置,打开场景,

WScript.Sleep 3000
WshShell.AppActivate "Mercury LoadRunner 控制器 - db.lrs - [*]"
'把Loadrunner置为激活状态

WScript.Sleep 1200
WshShell.Sendkeys "%{S}"
'执行行Alt+s 开始场景

WScript.Sleep 1000
WshShell.Sendkeys "{ENTER}"
'如果提示覆盖执行回车

WScript.Sleep 2000
WshShell.Run "cmd.exe /C tskill wlrun"
'运行2S(可设定)后 结束进程Wlrun

WScript.Sleep 2000
WshShell.Run "cmd.exe /C c:\\db1.lrs",1,true
'指定位置,打开第二个场景,

WScript.Sleep 3000
WshShell.AppActivate "Mercury LoadRunner 控制器 - db.lrs - [*]"
'把Loadrunner置为激活状态

WScript.Sleep 1200
WshShell.Sendkeys "%{S}"
'执行行Alt+s 开始场景

WScript.Sleep 1000
WshShell.Sendkeys "{ENTER}"
'如果提示覆盖执行回车

WScript.Sleep 2000
WshShell.Run "cmd.exe /C tskill wlrun"
'运行2S(可设定)后 结束进程Wlrun

把上述代码Copy到记事本中,重新保存为*.VBS

执行就可以实现

用VBS实现Loadrunner多场景的执行

用Bat也可以:

类如下东东:

SET M_ROOT="D:\Program Files\Mercury\LoadRunner\bin\"
%M_ROOT%\wlrun.exe -TestPath "c:\db.lrs" -Run

 

 

四、另一个:看不太懂,貌似是bat的

http://blog.csdn.net/m_star_jy_sy/archive/2008/10/28/3169296.aspx

@echo off & setlocal enableextensions enabledelayedexpansion

echo Wscript.Sleep 60000(单位毫秒) > %temp%\tmp$$$.vbs

 

SET LR_PATH="D:\Program Files\Mercury Interactive\Mercury LoadRunner\bin"

 

%LR_PATH%\wlrun.exe -TestPath "D:\Program Files\Mercury Interactive\Mercury LoadRunner\scenario\稳定性综合测试\Scenario_170.lrs" -Run
echo %time%

 

cscript. //nologo %temp%\tmp$$$.vbs

%LR_PATH%\wlrun.exe -TestPath "D:\Program Files\Mercury Interactive\Mercury LoadRunner\scenario\稳定性综合测试\Scenario_170.lrs" -Run

echo %time%

 

cscript. //nologo %temp%\tmp$$$.vbs

%LR_PATH%\wlrun.exe -TestPath "D:\Program Files\Mercury Interactive\Mercury LoadRunner\scenario\稳定性综合测试\Scenario_170.lrs" -Run

echo %time%


for %%f in (%temp%\tmp$$$.vbs) do if exist %%f del %%f
endlocal & goto :EOF

 

五、Python:定时运行脚本

#ps.py 

#coding=utf-8
import sys
import os
import datetime
import time

class ArgsDealwith:
    
    
def arg_environment(self, args):
        filepath 
= ('PYTHON_PATH''path')
        
for i in filepath:
            filename 
= os.environ.get(i,"%s is null." % i)
            
print '%s:' % i,'', filename

    
def arg_en(self, args):
        filepath 
= ('PYTHON_PATH''path')
        
for i in filepath:
            filename 
= os.environ.get(i,"%s is null." % i)
            
print '%s:' % i, ''''.join(filename.split(';'))

    
def arg_file(self, args):
        
if not args:
            
print 'Error: file name is null.'
        
else:
            
if len(args) == 1 and args[0].lower() == 'python_path':
                filename 
= os.environ.get(args[0], None)
                
if filename:
                    args 
= filename.split(';')
                
else:
                    
print 'Error: "%s" is null' % args[0]
                    exit()
                
            
for i in args:
                
if os.path.isfile(i):
                    
try:
                        execfile(i)
                    
except:
                        
print 'Error: "%s" run failed.' % i
                
else:
                    
print 'Error: Not found "%s" file.' % i
            
    
def arg_filetime(self, args):
        
if not args:
            
print 'Error: file name is null.'
        
elif len(args) % 2 != 0:
            
print 'Error: args isn't validate'
        
else:
            fileTimes 
= [i for i in args if args.index(i) % 2 != 0 ]
            
for i in fileTimes:
                
try:
                    fileTimes[fileTimes.index(i)] 
= int(i)
                
except Exception:
                    
print 'Error: time args isn't validate'
                    exit()
                
if i <= 0:
                    
print 'Error: time<=0'
                    exit()                 
                
            minTime 
= fileTimes[0]
            
for i in fileTimes:
                
if i < minTime:
                    minTime 
= i
            
            strTime 
= time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())
            tupleTime 
= tuple([int(i) for i in strTime.split('-')])
            begin 
= datetime.datetime(tupleTime[0], tupleTime[1], tupleTime[2], tupleTime[3], tupleTime[4], tupleTime[5])
            
            
            fileTimes 
= [[i, 0] for i in fileTimes]
            seconds 
= 0
            
while True:
                strTime 
= time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())
                tupleTime 
= tuple([int(i) for i in strTime.split('-')])
                end 
= datetime.datetime(tupleTime[0], tupleTime[1],tupleTime[2], tupleTime[3], tupleTime[4], tupleTime[5])
                
                time_sub 
= end - begin
                seconds 
= time_sub.seconds
                begin 
= end
                
for i in fileTimes:
                    i[
1+= seconds
                
                
for i in fileTimes:
                    
if i[1== 0:
                        self.arg_file( [args[args.index(str(i[0])) 
- 1] ] )
                    
elif i[1>= i[0]:
                        i[
1%= i[0]
                        self.arg_file( [args[args.index(str(i[0])) 
- 1] ] )
                        
if i[0] - i[1< minTime:
                            minTime 
= i[0] - i[1]
                
                time.sleep(minTime)

    
def arg_help(self, args):
        strHelp 
= "Usage: ps [-options] [args...] where option include:"
        strHelp 
+= """
        -? -help            print this help message
        -e -environment     print environment path
        -en                 print envrionment path per row
        -f -file:<file> [file2 file3...]
                            execute file(.py)      
        -ft -filetime:<file time> [file2 time2 file3 time3...]
                            execute file(.py) per time,
                            this run not stop,
                            but this command hasn't validate.  
                            time(seconds) must is interger and
                            not less than zero
"""
        
print strHelp
    
def arg_args():
    args_dic 
= {'arg_help' : ['-?''-help'], 'arg_environment' : ['-e''-environment'],
                
'arg_en' : ['-en'], 'arg_file' : ['-f''-file'], 'arg_filetime' : ['-ft''filetime']}
    argsCls 
= ArgsDealwith()
    
if len(sys.argv) <= 1:
        argsCls.arg_help(sys.argv)
    
else:
        argsFun 
= ''
        
for i in sys.argv[1:]:
            bMath 
= False
            
for j in args_dic.items():
                
if i in j[1]:
                    argsFun 
= j[0]
                    bMath 
= True
                    
break
            
if bMath:
                
break
        
if argsFun:
            
try:
                getattr(argsCls, argsFun)(sys.argv[
2:])    
            
except Exception, error:
                
print error
                exit()
        
else:
            
print 'Error: "%s" isn't validate arg.' % ' '.join(sys.argv[1:])
            
del argsCls                    

if __name__ == '__main__':
    arg_args()

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar