用于在 QC 测试用例中附加文件的 Excel VBA 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23870127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 03:15:01  来源:igfitidea点击:

Excel VBA code to attach files in QC Test Cases

excelvbaexcel-vbaqc

提问by Indra

I have a tool that capture screenshots of the application that we test at our workplace. Now once I complete my testing of a particular test case or scenarios, we attach the screenshot that we have taken to HP Quality Center manually.

我有一个工具可以捕获我们在工作场所测试的应用程序的屏幕截图。现在,一旦我完成了对特定测试用例或场景的测试,我们就会将手动截取到 HP Quality Center 的屏幕截图附上。

I want to automate this and make my tool to upload the word document to a test in QC Test Lab. Is this possible? If Yes, How can we do this in Excel VBA?

我想自动执行此操作并制作我的工具以将 word 文档上传到 QC 测试实验室中的测试。这可能吗?如果是,我们如何在 Excel VBA 中执行此操作?

Operations that we need to perform would be as below:

我们需要执行的操作如下:

  1. Connect to QC project with login credentials, domain & project details
  2. Pick a file(s) from a local folder
  3. Upload a file(s) to QC Test Lab, specific test case
  1. 使用登录凭据、域和项目详细信息连接到 QC 项目
  2. 从本地文件夹中选择一个文件
  3. 将文件上传到 QC 测试实验室,特定的测试用例

I used the below code, but getting error in that code. I marked it in the code below, please check below :

我使用了下面的代码,但在该代码中出现错误。我在下面的代码中标记了它,请检查下面:

Dim intTestID, FldPath, TestSetName, i
Dim TestSetFact, tsTreeMgr, tSetFolder, TestSetsList, theTestSet
Dim TestSetIdentifier, TSTestFact, TestSetTestsList, testInstanceF, aFilter
Dim lst, tstInstance

intTestID = "8968"

FldPath = TextBox3.Text '"Root\ProjFold\Release1\BRD"
TestSetName = ComboBox3.Text '"BRD" '

Set Connection = CreateObject("TDApiOle80.TDConnection")
Connection.InitConnectionEx Sheet2.Range("B1").Value2
Connection.Login TextBox1.Text, TextBox2.Text
Connection.Connect ComboBox1.Text, ComboBox2.Text

Set TestSetFact = Connection.TestSetFactory
Set tsTreeMgr = Connection.TestSetTreeManager

Set tSetFolder = tsTreeMgr.NodeByPath(FldPath)
Set TestSetsList = tSetFolder.FindTestSets(TestSetName)
Set theTestSet = TestSetsList.Item(1)
TestSetIdentifier = theTestSet.ID
i = 0
Set TSTestFact = theTestSet.TSTestFactory
Set TestSetTestsList = TSTestFact.NewList("")

Set testInstanceF = Connection.TSTestFactory
Set aFilter = testInstanceF.Filter

aFilter.Filter("TC_TEST_ID") = intTestID
Set lst = testInstanceF.NewList(aFilter.Text)
Set tstInstance = lst.Item(1)   <---------------- getting error here
MsgBox (tstInstance.Field("TS_Name"))
'tstInstance.Status = "Failed"
'tstInstance.Field("TC_STATUS") = Item1.Status '"Passed"
'tstInstance.Post
Dim RunF, runName, NewRun, runStepF, runlst, Item1, runStep2

MsgBox (tstInstance.Field("TS_Subject"))
Set RunF = tstInstance.RunFactory
runName = "Run_" & Month(Date) & "-" & Day(Date) & "_" & Hour(Now) & "-" & Minute(Now) &         "-" & Second(Now)
Set NewRun = RunF.AddItem(Null)
NewRun.Status = "Passed"
NewRun.Name = runName
NewRun.Post
NewRun.CopyDesignSteps
NewRun.Post
Set runStepF = NewRun.StepFactory
Set runlst = runStepF.NewList("")
For Each Item1 In runlst
      Set runStep2 = Item1
      runStep2.Status = "Passed" '
      runStep2.Field("ST_ACTUAL") = "As Expected"
      runStep2.Post
Next
'tstInstance.Refresh
tstInstance.Status = "Failed"

tstInstance.Post
Connection.DisconnectProject
Connection.ReleaseConnection
'Set QC = Nothing
Set Connection = Nothing

回答by cflow

The error is occurring because the array of objects is not returning. You need to check if the Filtergives you a list of results before assuming that lst.Item(1)exists.

发生错误是因为对象数组未返回。Filter在假设lst.Item(1)存在之前,您需要检查它是否为您提供了结果列表。

For instance:

例如:

If lst.Count > 0 Then Set tstInstance = lst.Item(1)