TA的每日心情 | 郁闷 2018-11-15 14:58 |
---|
签到天数: 2 天 连续签到: 2 天 [LV.1]测试小兵
|
Multi Test Manager选择用例需要一个个选择,效率很低,下面是自己写的一个脚本,选择批量用例和执行。
'创建oMTM自动化模型组件
Set oMTM = CreateObject("MultiTestManager.Application")
'设置为可见模式
oMTM.Visible = True
Dim sourcepath, fPath
sourcepath = "D:\QTP\"
fPath = "D:\QTP\QTP执行.vbs"
'加载需要执行的脚本,并设置为True
sPath = scriptPath(sourcepath)
Set fso = CreateObject("Scripting.FileSystemObject")
'判断执行脚本是否有存在
If fso.FileExists(fPath) Then
fso.DeleteFile fPath,True
End If
'创建执行脚本
Set objTStream = fso.OpenTextFile(fPath, 2, true)
objTStream.WriteLine "Set oMTM = CreateObject(""MultiTestManager.Application"")"
objTStream.WriteLine "Set oReportSettings = oMTM.Preferences.ReportSettings"
objTStream.WriteLine "Set oRunSettings = oMTM.Preferences.RunSettings"
objTStream.WriteLine "oMTM.Visible = True"
objTStream.WriteLine "oRunSettings.CloseQuickTest = True"
objTStream.WriteLine "oRunSettings.CloseTestManager = True"
objTStream.WriteLine "oReportSettings.CreateReport = True "
objTStream.WriteLine "oReportSettings.ReportName = ""QTP执行报告"" "
objTStream.WriteLine "oReportSettings.ViewReport = True"
For j=LBound(sPath) to UBound(sPath)
'利用TextStream对象来将字符串写入文件
objTStream.WriteLine sPath(j)
Next
objTStream.WriteLine "oMTM.Run"
objTStream.WriteLine "While oMTM.IsRunning : Wend"
objTStream.WriteLine "Set oMTM = Nothing "
objTStream.WriteLine "Set oRunSettingss = Nothing"
objTStream.WriteLine "Set oReportSettings = Nothing"
'释放TextStream对象
objTStream.close
Set fso = Nothing
'批量执行用例
set ws = CreateObject("wscript.shell")
ws.run fPath
Set ws = nothing
'获取脚本路径
Function scriptPath(sourcepath)
Dim fso,objset,objFolders,FolderName,i
Dim myArray()
i = 0
Set fso = CreateObject("Scripting.FileSystemObject")
'使用GetFolder方法来返回Folder对象
Set objset = fso.getFolder(sourcepath)
'SubFolders属性将返回所有子文件夹对应的Folder集合
Set objFolders = objset.SubFolders
'遍历Folder集合,统计出共有多少个文件夹,及相关文件夹的名字
For Each objFolder in objFolders
Set objset1=fso.GetFolder(objFolder)
Set objFloders1=objset1.SubFolders
For each objFolder1 in objFloders1
ReDim preserve myArray(i) '设置动态数组
myArray(i) = "oMTM.AddTestScript """ & objFolder1 & """,True"
i = i + 1
next
Next
scriptPath = myArray
Set fso = Nothing
End function |
|