生命是个舞台,不用排练,尽情表演,感动过的片段百看不厌。

VBS典型好用的测试脚本

上一篇 / 下一篇  2011-05-30 22:43:21 / 个人分类:测试脚本

调用测试程序,打开某个指定文件夹里面所有“*.*”格式的文件,执行某些可控操作,然后存盘。

Sub testCases()
   
    '打开一个文件夹(包括子文件夹)中的所有doc文件,执行相同的操作。
    '吴增念 测试脚本
   
    Dim strPath As String
    Dim strFileName As String
    Dim docOutline As Document
    Dim strFileNames() As String
    Dim lFileNames As Long
   
    '获取文件夹路径
    strPath = ActiveDocument.Path '(也可以指定文件夹路径 strPath = "c:\testCase" )
   
    'call 下面一段函数。(路径、后缀、文件名)
    lFileNames = TreeSearch(strPath, "*.doc", strFileNames())
   
    '从第2个文件开始执行操作
    For idx = 2 To lFileNames
   
        '/////////////////////////////////////////////////////////////////
        '打开指定文件名
        strFileName = strFileNames(idx)
        If Len(strFileName) Then
            Set docOutline = Application.Documents.Open(strFileName)
           
            'to do

            '关闭执行后的文件,不保存。(保存:wdPromptToSaveChanges ; 取消:wdSaveChanges)
           
            ActiveWindow.View.Type = wdWebView
            Selection.Orientation = wdTextOrientationVerticalFarEast
            ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:=6, DefaultTableBehavior.:=wdWord9TableBehavior, AutoFitBehavior.:=wdAutoFitFixed
            ActiveDocument.Shapes.Range(1).Select        

            Selection.Delete            

            ActiveDocument.Save
            
        End If
    Next
End Sub


Public Function TreeSearch(ByVal strPath As String, ByVal strFileSpec As String, strFiles() As String) As Long
Static lFiles As Long
Dim lTemp As Long
Dim lIndex As Long
Dim strDir As String
Dim strSubDirs() As String

    If Right(strPath, 1) <> "\" Then
        strPath = strPath & "\"
    End If
   
    strDir = Dir(strPath & strFileSpec)
    Do While Len(strDir)
        lFiles = lFiles + 1
        ReDim Preserve strFiles(1 To lFiles)
        strFiles(lFiles) = strPath & strDir
        strDir = Dir
    Loop
       
    lIndex = 0
    strDir = Dir(strPath & "*.*", vbDirectory)
    Do While Len(strDir)
        lPos = Len(strDir)
        If Right(strDir, lPos) <> "." And Right(strDir, lPos) <> ".." Then
            If GetAttr(strPath & strDir) And vbDirectory Then
                lIndex = lIndex + 1
                ReDim Preserve strSubDirs(1 To lIndex)
                strSubDirs(lIndex) = strPath & strDir & "\"
            End If
        End If
          
        strDir = Dir
    Loop
   
    For lTemp = 1 To lIndex
           Call TreeSearch(strSubDirs(lTemp), strFileSpec, strFiles())
    Next lTemp
   
    TreeSearch = lFiles
End Function


TAG: Offixe vbs VBS 测试脚本

 

评分:0

我来说两句

wuzengshen

wuzengshen

2007年6月11日加入金山,先后参与了金山毒霸文件引擎测试,病毒样本测试,之后转战桌面办公软件测试,期间支援过金山云测试。前面主要负责桌面软件的测测试设计、测试执行、自动化设计、脚本开发等工作,后面主要负责企业项目测试管理、产品稳定性测试研究工作。

日历

« 2024-04-20  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 27163
  • 日志数: 30
  • 建立时间: 2011-05-18
  • 更新时间: 2014-02-23

RSS订阅

Open Toolbar