51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3816|回复: 7
打印 上一主题 下一主题

[原创] 问个问题,VBS如何修改QC所有运行域的值?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-10-23 23:20:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 lyscser 于 2010-10-24 11:39 编辑

我查了一下,run表里面没有trigger,数据应该都可以用vbs改,就是不知道咋改,只知道运行结果状态这一个字段的修改,不知道其他的有没有好的方法

Set Wshshell = CreateObject("Wscript.shell")
Set TDConn = CreateObject("TDApiOle80.TDConnection.1")

Set tsTreeMgr = TDConn.TestSetTreeManager
Set tsFolder = tsTreeMgr.NodeByPath("Root\" & Trim(tsFolderName))
Set tsList = tsFolder.FindTestSets(tSetName)
Set theTestSet = tsList.Item(1)
Set TSTestFact = theTestSet.TSTestFactory
Set TestSetTestsList = TSTestFact.NewList("")

testCaseNum = TestSetTestsList.Count

For i = 1 To testCaseNum
TestSetTestsList.Item(i).Status = "Passed"
TestSetTestsList.Item(i).Post
Next

Set TestSetTestsList = Nothing
Set TSTestFact = Nothing
Set theTestSet = Nothing
Set tsList = Nothing
Set tsFolder = Nothing
Set tsTreeMgr = Nothing
Set TDConn = Nothing
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2010-10-24 11:39:32 | 只看该作者
run表的顺序我已经用QTP打出来了

Set fieldList = TDConn.Fields("run")
For i = 1 to fieldList.Count
   Set colField = fieldList.Item(i)
   Print "'The "&i&"th item is " & colField.Name
Next

'The 01th item is RN_OS_BUILD
'The 02th item is RN_OS_NAME
'The 03th item is RN_OS_SP
'The 04th item is RN_TEST_ID
'The 05th item is RN_TESTCYCL_ID
'The 06th item is RN_TEST_VERSION
'The 07th item is RN_CYCLE
'The 08th item is RN_TEST_INSTANCE
'The 09th item is RN_TESTER_NAME
'The 10th item is RN_DURATION
'The 11th item is RN_ATTACHMENT
'The 12th item is RN_PATH
'The 13th item is RN_OS_CONFIG
'The 14th item is RN_CYCLE_ID
'The 15th item is RN_VC_VERSION
'The 16th item is RN_VC_LOKEDBY
'The 17th item is RN_VC_STATUS
'The 18th item is RN_RUN_ID
'The 19th item is RN_RUN_NAME
'The 20th item is RN_EXECUTION_DATE
'The 21th item is RN_EXECUTION_TIME
'The 22th item is RN_HOST
'The 23th item is RN_STATUS
'The 24th item is RN_RUN_VER_STAMP
'The 25th item is RN_USER_01
'The 26th item is RN_USER_02
'The 27th item is RN_USER_03
'The 28th item is RN_USER_04
'The 29th item is RN_USER_10
'The 30th item is RN_USER_05
'The 31th item is RN_USER_11
'The 32th item is RN_USER_06
'The 33th item is RN_USER_12
'The 34th item is RN_USER_07
'The 35th item is RN_USER_08
'The 36th item is RN_USER_09
'The 37th item is RN_VTS
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2010-10-24 19:21:21 | 只看该作者
嘿嘿,琢磨了一下,终于弄清楚了,要是这些方法有中文说明文档多好啊……

Set tsTreeMgr = TDConn.TestSetTreeManager
Set tsFolder = tsTreeMgr.NodeByPath("Root\" & Trim(tsFolderName))
Set tsList = tsFolder.FindTestSets(tSetName)

Set theTestSet = tsList.Item(1)

Set TSTestFact = theTestSet.TSTestFactory
Set TestSetTestsList = TSTestFact.NewList("")
testCount = TestSetTestsList.Count

For i = 1 To testCount
        Set TheSpecifiedTest = TestSetTestsList.Item(i)
        Set TheRunFactory = TheSpecifiedTest.RunFactory
        Set theRun = TheRunFactory.AddItem("Run_"&Month(Date)&"-"&Day(Date)&"_"&Hour(Time)&"-"&Minute(Time)&"-"&Second(Time))
        theRun.status = "Passed"
        theRun.Field("RN_HOST") = "FUDANXIANG"
        theRun.Field("RN_DURATION") = "125"
        theRun.Field("RN_TESTER_NAME") = "admin"
        theRun.Post
Next
回复 支持 反对

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2010-10-24 19:23:18 | 只看该作者
不过这个办法无法修改现有的运行,只能新增一个现有的运行
这个地儿的instance id可以根据实际要修改的时间生成
Set theRun = TheRunFactory.AddItem("Run_"&Month(Date)&"-"&Day(Date)&"_"&Hour(Time)&"-"&Minute(Time)&"-"&Second(Time))
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2010-10-25 08:42:54 | 只看该作者
很好很强大
回复 支持 反对

使用道具 举报

该用户从未签到

6#
 楼主| 发表于 2010-10-27 23:46:52 | 只看该作者
终极版本,作弊无极限……造成一切后果本人谢绝承担责任
Public Sub Modify_QC_Run_Fields(fileFullPath,myStatus,newVersionNo)

        'On Error Resume Next

        Set Wshshell = CreateObject("Wscript.shell")
        Set TDConn = CreateObject("TDApiOle80.TDConnection.1")
        Set objExcel = CreateObject("Excel.Application")
        Set objWorkbook = objExcel.Workbooks.Open(fileFullPath,False,True)

        If        TDConn.Connected = False Then  
                TDConn.InitConnectionEx "http://192.168.1.103:8080/qcbin"
                TDConn.Login "LIUYI",""
                TDConn.Connect "MYDOM","automation"
        Else
                TDConn.Disconnect()
                TDConn.Logout()
                TDConn.ReleaseConnection()
                TDConn.InitConnectionEx "http://192.168.1.103:8080/qcbin"
                TDConn.Login "LIUYI",""
                TDConn.Connect "MYDOM","automation"
        End If

        intRow = 1

        Do Until Trim(objExcel.Cells(intRow,1).Value) = ""

                tsFolderName = objExcel.Cells(intRow, 1).Value
                tSetName = objExcel.Cells(intRow, 2).Value
               
                myHostint = int((286-271+1)*rnd+271)
                myHost = "CNSH020"&Trim(myHostint)
               
                Set tsTreeMgr = TDConn.TestSetTreeManager
                Set tsFolder = tsTreeMgr.NodeByPath("Root\" & Trim(tsFolderName))
                Set tsList = tsFolder.FindTestSets(tSetName)
  
          If  tsFolder Is Nothing Then
                        Wshshell.Popup "找不到路径【" & nPath&"】",1,"运行时错误:",0
                        Set tsList = Nothing
                        Set tsFolder = Nothing
                        Set tsTreeMgr = Nothing
                        Set TDConn = Nothing
                        Set Wshshell = Nothing
          End If
  
                If  tsList.Count < 1 Then
                        Wshshell.Popup "找不到测试集!【" & tSetName&"】",1,"运行时错误:",0
                        Set tsList = Nothing
                        Set tsFolder = Nothing
                        Set tsTreeMgr = Nothing
                        Set TDConn = Nothing
                        Set Wshshell = Nothing
                End If
               
                Set theTestSet = tsList.Item(1)
               
                theTestSet.Field("CY_USER_01") = newVersionNo
                theTestSet.Field("CY_STATUS") = "Open"
                theTestSet.Field("CY_OPEN_DATE") = Date
                theTestSet.Post
  
                Set TSTestFact = theTestSet.TSTestFactory
                Set TestSetTestsList = TSTestFact.NewList("")       
          testCount = TestSetTestsList.Count
  
          For i = 1 To testCount
         
                        Set TheSpecifiedTest = TestSetTestsList.Item(i)
                        theTestId= TheSpecifiedTest.TestId
                        stepCount = TheSpecifiedTest.Field("TS_STEPS")
  
                   Select Case TheSpecifiedTest.Field("TS_TYPE")
                           Case "MANUAL"
                                   mySpecifiedHost = "HSH-9376"
                                   mySpecifiedTester = "LIUYI"
                           Case "QUICKTEST_TEST"
                                   mySpecifiedHost = myHost
                                   mySpecifiedTester = "admin"
                           Case Else
                                   Wscript.Echo "您选择了一个既非QTP脚本也非手工测试案例的实例,请确认!"
                   End Select
                     
                        Set MyRunInstanceFactory = TheSpecifiedTest.RunFactory
                        Set MyRunInstance = MyRunInstanceFactory.AddItem("Run_"&Month(Date)&"-"&Day(Date)&"_"&Hour(Time)&"-"&Minute(Time)&"-"&Second(Time))

                        Set TheTestStepFact = MyRunInstance.StepFactory
                       
                        Set TDCom = TDConn.Command
                        TDCom.CommandText = "select * from dessteps where ds_test_id = "&theTestId
                        Set RecSet = TDCom.Execute
                        RecSet.First
                       
                        For v = 1 to stepCount
                                operDesc = RecSet.FieldValue("DS_DESCRIPTION")
                                expectDesc = RecSet.FieldValue("DS_EXPECTED")
                                Set TheTestRunStep  = TheTestStepFact.AddItem(NULL)
                                TheTestRunStep.Field("ST_STEP_NAME") = "步骤 "&v
                                TheTestRunStep.Field("ST_STATUS") = myStatus
                                TheTestRunStep.Field("ST_EXECUTION_DATE") = Date
                                TheTestRunStep.Field("ST_EXECUTION_TIME") = Time
                                TheTestRunStep.Field("ST_DESCRIPTION") = operDesc
                                TheTestRunStep.Field("ST_EXPECTED") = expectDesc
                                TheTestRunStep.Field("ST_ACTUAL") = expectDesc
                                TheTestRunStep.Field("ST_PATH") = TheSpecifiedTest.Name
                                TheTestRunStep.Field("ST_STEP_ORDER") = v
                                TheTestRunStep.Post
                                If         v < stepCount Then
                                                RecSet.Next
                                End If
                        Next
            
                        MyRunInstance.Field("RN_STATUS") = myStatus
                        MyRunInstance.Field("RN_HOST") = mySpecifiedHost
                        MyRunInstance.Field("RN_DURATION") = Trim(Int((180-60+1)*Rnd+60))
                        MyRunInstance.Field("RN_TESTER_NAME") = mySpecifiedTester
                        MyRunInstance.Field("RN_EXECUTION_DATE") = Date
                        MyRunInstance.Field("RN_EXECUTION_TIME") = Time
                        MyRunInstance.Post
            
                        TheSpecifiedTest.Field("TC_ACTUAL_TESTER") = mySpecifiedTester
                        TheSpecifiedTest.Field("TC_EXEC_DATE") = Date
                        TheSpecifiedTest.Field("TC_EXEC_TIME") = Time
                        TheSpecifiedTest.Field("TC_STATUS") = myStatus
                        TheSpecifiedTest.Post

                        Set RecSet = Nothing
                        Set TDCom = Nothing
                        Set TheTestRunStep = Nothing
                        Set TheTestStepFact = Nothing
                        Set MyRunInstance = Nothing
                        Set MyRunInstanceFactory = Nothing
                        Set TheSpecifiedTest = Nothing
          Next
  
                Set TestSetTestsList = Nothing
                Set TSTestFact = Nothing
                Set theTestSet = Nothing
                Set tsList = Nothing
                Set tsFolder = Nothing
                Set tsTreeMgr = Nothing
               
                intRow = intRow + 1
        Loop

        objExcel.Quit

        Set objWorkbook = Nothing
        Set objExcel = Nothing
        Set TDConn = Nothing

End Sub

Call Modify_QC_Run_Fields("D:\Documents\测试工具文档\VBS\my_testset.xls","Passed","MYTest-NEWTest1.0.2")
回复 支持 反对

使用道具 举报

  • TA的每日心情
    开心
    2015-10-19 13:26
  • 签到天数: 2 天

    连续签到: 2 天

    [LV.1]测试小兵

    7#
    发表于 2010-11-1 22:43:41 | 只看该作者
    本帖最后由 kavensyw 于 2010-11-1 23:14 编辑

    其实说白了,对QC的修改无非两种途径,一种是用TDConnection,另一种直接修改数据库。
    如果光要改状态,不想改运行时间...其他关联的字段,用ADO直接修改数据库也可以

    如果对QC的表结构不是很了解,当然建议用TDConnection则更安全一点,它其实也是修改数据库,不过考虑了关联表的影响


    至于QC中文说明文档,我记得QC栏有的啊,我这来发中一份,有兴趣可以看看。英文的压缩后超过2M,懒得分解了。
    超喜欢这张Object Model,条理很好,有了这张图,要修改什么字段,到哪个对象调用方法或属性基本就知道了
    最常用的就是中间一部分对象了

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

    x
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    8#
     楼主| 发表于 2010-11-1 23:26:01 | 只看该作者
    多谢,这份文档我也有,不过你得考虑两种情况:
    1、不给dml执行的权限,QC数据库不许随便修改
    2、有些field通过tdc是无法修改滴,比如RN_PATH、RN_RUN_VER_STAMP之类的……
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-11-22 02:54 , Processed in 0.074157 second(s), 28 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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