51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1991|回复: 0
打印 上一主题 下一主题

[原创] Multi Test Manager选择批量用例和执行

[复制链接]
  • TA的每日心情
    郁闷
    2018-11-15 14:58
  • 签到天数: 2 天

    连续签到: 2 天

    [LV.1]测试小兵

    跳转到指定楼层
    1#
    发表于 2012-2-24 16:59:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    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
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-18 07:43 , Processed in 0.062552 second(s), 26 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表