51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2879|回复: 1
打印 上一主题 下一主题

[原创] OTA第一篇用例根据自定义格式批量导出....

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-1-18 12:02:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
OTA第一篇用例根据自定义格式批量导出....
     大家可以参考一下代码 修改为自己定义的格式,导出的文件格式为WORD
   实现了功能,代码质量没有考虑 哈哈,请大家别介意

Dim QCConnection As TDConnection
    Dim Test As Test
    Dim TestFactory As TestFactory
    Dim TestList
    Dim StepFactory As DesignStepFactory
    Dim Step As DesignStep
    Dim StepList
    Dim str As String

    Dim documentName As String
    Dim wordApp As Word.Application
    documentName = "软件测试说明.doc"
    Dim conn     As adodb.Connection
    Dim strConnect     As String
    Dim rs     As New adodb.Recordset
    Dim strSql     As String
    Set wordApp = CreateObject("Word.Application")
     '使文档可见 0不可见
    wordApp.Application.Visible = 0
    Dim myDoc As Word.Document
    Set myDoc = wordApp.Documents.Add() '页面
    With wordApp
Set QCConnection = New TDAPIOLELib.TDConnection
     QCConnection.InitConnectionEx "http://XXXXXXX/qcbin"
     QCConnection.ConnectProjectEx "DEFAULT", "XXXXXXX", "XXXXXXX", "XXXXXXX"
     Set TestFactory = QCConnection.TestFactory

For Each Test In TestList
         .Selection.Font.name = "黑体"
         .Selection.Font.Size = 16
         .Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
         .Selection.TypeText Text:="测试用例设计单"
         .Selection.EndKey Unit:=wdStory
         
         
         .Selection.Font.name = "宋体"
         .Selection.Font.Size = 12
         .Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
         .Selection.EndKey Unit:=wdStory
        
        
        Set StepFactory = Test.DesignStepFactory
        Set StepList = StepFactory.NewList("")
        
         Set mytable = .ActiveDocument.Tables.Add(.Selection.Range, StepList.Count + 13, 5)
                With .Selection.Tables(1)
                    If .Style <> "网格型" Then
                        .Style = "网格型"
                    End If
                    .ApplyStyleHeadingRows = True
                    .ApplyStyleLastRow = True
                    .ApplyStyleFirstColumn = True
                    .ApplyStyleLastColumn = True
                End With
               
                '配置表格
                mytable.Columns(1).Width = 20
                mytable.Columns(3).Width = 140
                mytable.Cell(1, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(2, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(3, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(4, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(5, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(6, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(7, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(8, 1).Select
               .Selection.MoveRight wdCharacter, 4, wdExtend
               .Selection.Cells.Merge
            
               
               
                mytable.Cell(1, 2).Select
               .Selection.MoveRight wdCharacter, 2, wdExtend
               .Selection.Cells.Merge
            
               
               mytable.Cell(3, 2).Select
               .Selection.MoveRight wdCharacter, 2, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(4, 2).Select
               .Selection.MoveRight wdCharacter, 2, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(5, 2).Select
               .Selection.MoveRight wdCharacter, 2, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(6, 2).Select
               .Selection.MoveRight wdCharacter, 2, wdExtend
               .Selection.Cells.Merge
               
                mytable.Cell(7, 2).Select
               .Selection.MoveRight wdCharacter, 2, wdExtend
               .Selection.Cells.Merge
               
               
                mytable.Cell(StepList.Count + 10, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
            
               
               mytable.Cell(StepList.Count + 11, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(StepList.Count + 12, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(StepList.Count + 13, 1).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               
                mytable.Cell(StepList.Count + 10, 4).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
            
               
               mytable.Cell(StepList.Count + 11, 2).Select
               .Selection.MoveRight wdCharacter, 3, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(StepList.Count + 12, 4).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
               mytable.Cell(StepList.Count + 13, 4).Select
               .Selection.MoveRight wdCharacter, 1, wdExtend
               .Selection.Cells.Merge
               
            .Selection.EndKey Unit:=wdStory
            .Selection.InsertBreak Type:=wdPageBreak
               
            '输入字段名称
            mytable.Cell(1, 1).Range.InsertAfter "测试用例名称"
            mytable.Cell(2, 1).Range.InsertAfter "测试用例标识"
            mytable.Cell(2, 3).Range.InsertAfter "测试追踪"
            mytable.Cell(3, 1).Range.InsertAfter "测试用例描述"
            mytable.Cell(4, 1).Range.InsertAfter "测试方法"
            mytable.Cell(5, 1).Range.InsertAfter "测试类型"
            mytable.Cell(6, 1).Range.InsertAfter "前提和约束(包括初始化要求)"
            mytable.Cell(7, 1).Range.InsertAfter "测试终止条件"
            mytable.Cell(8, 1).Range.InsertAfter "测试过程"
            mytable.Cell(9, 1).Range.InsertAfter "序号"
            mytable.Cell(9, 2).Range.InsertAfter "输入及操作步骤"
            mytable.Cell(9, 3).Range.InsertAfter "期望测试结果"
            mytable.Cell(9, 4).Range.InsertAfter "评估准则"
            mytable.Cell(9, 5).Range.InsertAfter "实际测试结果"
            mytable.Cell(StepList.Count + 10, 1).Range.InsertAfter "设计人员"
            mytable.Cell(StepList.Count + 10, 3).Range.InsertAfter "设计日期"
            mytable.Cell(StepList.Count + 11, 1).Range.InsertAfter "问题标识"
            mytable.Cell(StepList.Count + 12, 1).Range.InsertAfter "执行结果"
            mytable.Cell(StepList.Count + 12, 3).Range.InsertAfter "测试人员"
            mytable.Cell(StepList.Count + 13, 1).Range.InsertAfter "测试监督员"
            mytable.Cell(StepList.Count + 13, 3).Range.InsertAfter "测试执行时间"
            
            str = CaseString(Test("ts_description"))
            str = Replace(str, "<html><body>", "")
            str = Replace(str, "&lt;", "<")
            str = Replace(str, "&gt;", ">")
            str = Replace(str, "</body></html>", "")
            str = Replace(str, "<br>", "")
            str = Replace(str, "<i>", "")
            str = Replace(str, "</i>", "")
            str = Replace(str, "<b>", "")
            str = Replace(str, "</b>", "")
            str = Replace(str, "<u>", "")
            str = Replace(str, "</u>", "")
            str = Replace(str, vbCrLf, "")
            Dim MyArray
            MyArray = Split(str, "〓", -1, 1)
         
            mytable.Cell(1, 2).Range.InsertAfter Test.name
            mytable.Cell(2, 2).Range.InsertAfter ""        '用例标示
            mytable.Cell(2, 4).Range.InsertAfter ""        '用例追踪
            mytable.Cell(3, 2).Range.InsertAfter MyArray(0)
            mytable.Cell(4, 2).Range.InsertAfter ""
            mytable.Cell(5, 2).Range.InsertAfter Test.Type
            mytable.Cell(6, 2).Range.InsertAfter MyArray(1)
            mytable.Cell(7, 2).Range.InsertAfter MyArray(2)
            mytable.Cell(StepList.Count + 10, 2).Range.InsertAfter Test("ts_responsible")
            mytable.Cell(StepList.Count + 10, 4).Range.InsertAfter Test("ts_creation_date")
            mytable.Cell(StepList.Count + 11, 2).Range.InsertAfter ""
            mytable.Cell(StepList.Count + 12, 2).Range.InsertAfter ""
            mytable.Cell(StepList.Count + 12, 4).Range.InsertAfter ""
            mytable.Cell(StepList.Count + 13, 2).Range.InsertAfter ""
            mytable.Cell(StepList.Count + 13, 4).Range.InsertAfter ""
            
            Dim I As Integer
            I = 1
            Dim StepName As String
            Dim StepDescription As String
            Dim StepExpectedResult As String
        For Each Step In StepList
              
              StepName = Step.StepName
              StepDescription = Step.StepDescription
              StepExpectedResult = Step.StepExpectedResult
              StepName = Replace(StepName, "步骤", "")
              StepName = Replace(StepName, "Step", "")
               StepName = Replace(StepName, "<html><body>", "")
               StepName = Replace(StepName, "&lt;", "<")
               StepName = Replace(StepName, "&gt;", ">")
               StepName = Replace(StepName, "</body></html>", "")
                StepName = Replace(StepName, "<br>", vbCrLf + "")
               
                StepDescription = Replace(StepDescription, "<html><body>", " ")
                StepDescription = Replace(StepDescription, "&lt;", "<")
               StepDescription = Replace(StepDescription, "&gt;", ">")
               StepDescription = Replace(StepDescription, "</body></html>", "")
                StepDescription = Replace(StepDescription, "<br>", vbCrLf + "")
               
                StepExpectedResult = Replace(StepExpectedResult, "<html><body>", "")
                StepExpectedResult = Replace(StepExpectedResult, "&lt;", "<")
               StepExpectedResult = Replace(StepExpectedResult, "&gt;", ">")
               StepExpectedResult = Replace(StepExpectedResult, "</body></html>", "")
                StepExpectedResult = Replace(StepExpectedResult, "<br>", vbCrLf + "")
            mytable.Cell(9 + I, 1).Range.InsertAfter StepName
            mytable.Cell(9 + I, 2).Range.InsertAfter StepDescription
            mytable.Cell(9 + I, 3).Range.InsertAfter StepExpectedResult

            I = I + 1
        Next
        
    Next

End With
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    郁闷
    2014-10-28 09:30
  • 签到天数: 3 天

    连续签到: 1 天

    [LV.2]测试排长

    2#
    发表于 2014-10-28 09:31:15 | 只看该作者
    OTA是这样测的吗?疑惑啊~!
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-5-13 03:43 , Processed in 0.067952 second(s), 26 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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