我最近创建了一个新的恢复方案,我们希望将其添加到所有现有的数百个运行脚本中。
不幸的是,将其设置为默认值仅适用于新脚本创建,并且不会将其追溯地添加到所有现有脚本中。
我已经问过HP支持,他们建议您需要在每个脚本的测试设置|恢复中为每个脚本添加它。我已要求他们将其列为未来版本的功能请求,以便将来能够实现并帮助人们。
我们现在要做的是创建一个函数或脚本,我们可以在质量中心列出文件夹并浏览其中的所有脚本,然后更新它们。
然而,我们注意到,在运行时检查脚本,编辑脚本并将其签入是不行的,因为Quality Center似乎以只读方式运行所有脚本。
是否有其他方法可以添加恢复方案,更重要的是,将其保存到脚本中?
我发现您可以在运行时动态添加恢复方案,但问题是,恢复方案在同一次运行中不起作用,只在下一次运行时,因此脚本必须完全停止并重新开始每个剧本每次都有。
感谢任何帮助。感谢
答案 0 :(得分:1)
Sub test()
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True
qtApp.TDConnection.Connect "http://qcserver/qcbin", _
"MY_DOMAIN", "My_Project", "USER_NAME", "PASSWORD", False
blsSupportsVerCtrl = qtApp.TDConnection.SupportVersionControl ' Check whether the project supports version control
Recovery_scenario_path = "[ALM\Resources] Resources\Subject\Library\Recovery.qrs"
Set testF = qtApp.TDconnection.TestFactory
Set tFilter = testF.Filter
tFilter.Filter("TS_TYPE") = "QUICKTEST_TEST"
Set tList = tFilter.NewList()
For Each aT In tList
Set folderF = qtApp.TDconnection.TestFolderFactory
Set fFilter = folderF.Filter
fFilter.Filter("AL_ITEM_ID") = aT.FolderID
test_script_path = ""
Set fList = fFilter.NewList()
If fList.count = 1 Then
test_script_path = fList(1).Path & "\" & aT.Name
Else
MsgBox "Unable to determine the test script path"
Exit Sub
End If
qtApp.Open "[ALM\Subject] " & test_script_path ' Test path in HP ALM
If blsSupportsVerCtrl Then ' If the project supports version control
qtApp.test.CheckOut ' Check out the test
End If
Set qtTestRecovery = qtApp.test.Settings.Recovery
If qtTestRecovery.Count > 0 Then ' If there are any default scenarios specified for the test
qtTestRecovery.RemoveAll ' Remove them
End If
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName1", 1
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName2", 2 '
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName3", 3
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName4", 4
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName5", 5
For intIndex = 1 To qtTestRecovery.Count ' Iterate the scenarios
qtTestRecovery.Item(intIndex).Enabled = True ' Enable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
Next
qtTestRecovery.Enabled = True
qtTestRecovery.SetActivationMode "OnError"
qtApp.test.Save
If blsSupportsVerCtrl And qtApp.test.VerCtrlStatus = "CheckedOut" Then ' If the test is checked out
qtApp.test.CheckIn ' Check it in
End If
Next
qtApp.TDConnection.Disconnect
qtApp.Quit
Set App = Nothing
End Sub
答案 1 :(得分:0)
感谢Barney的代码基础。我做了一些修改以更好地适应我们的目的。
我们已经补充说 - 检查脚本是否已经签出并将其添加到文本日志文件中。 - 电子表格的填充以及文件夹/子文件夹中的所有测试完整路径
Sub UpdateRecoveryScenarios()
Dim vLog
Dim vTFName As String
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True
qtApp.TDConnection.Connect "http://qcserver/qcbin", _
"MY_DOMAIN", "My_Project", "username", "password", False
blsSupportsVerCtrl = qtApp.TDConnection.SupportVersionControl ' Check whether the project supports version control
Set sh = ThisWorkbook.Sheets("Test List")
Call PopulateTestNames 'populates all scripts within mainscripts
Recovery_scenario_path = "[ALM\Resources] Resources\Subject\Library\Recovery.qrs"
vLog = Date
N = sh.Cells.CurrentRegion.Rows.Count 'sets N as number of populated rows
For i = 1 To N
qtApp.Open sh.Cells(i, 1) ' Test path in HP ALM
If qtApp.test.VerCtrlStatus = "CheckedOut" Then
vLog = vLog & "; " & sh.Cells(i, 1)
Else
qtApp.test.CheckOut ' Check out the test
Set qtTestRecovery = qtApp.test.Settings.Recovery
If qtTestRecovery.Count > 0 Then ' If there are any default scenarios specified for the test
qtTestRecovery.RemoveAll ' Remove them
End If
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName1", 1
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName2", 2 '
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName3", 3
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName4", 4
qtTestRecovery.Add Recovery_scenario_path, "ScenarioName5", 5
For intIndex = 1 To qtTestRecovery.Count ' Iterate the scenarios
qtTestRecovery.Item(intIndex).Enabled = True ' Enable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
Next
qtTestRecovery.Enabled = True
qtTestRecovery.SetActivationMode "OnError"
qtApp.test.Save
If blsSupportsVerCtrl And qtApp.test.VerCtrlStatus = "CheckedOut" Then ' If the test is checked out
qtApp.test.CheckIn ' Check it in
End If
End If
Next
qtApp.TDConnection.Disconnect
qtApp.Quit
Set App = Nothing
'create log
If Len(vLog) > 10 Then
vLogArr = Split(vLog, "; ")
vCount = UBound(vLogArr)
vDate = Date
vDate = Replace(vDate, "/", ".")
vTFName = "C:\Update Recovery Scenarios\Failed to Update RS Log - " & vDate & ".txt"
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(vTFName, True)
For i = 0 To vCount
a.WriteLine (vLogArr(i))
a.WriteLine Chr(13)
Next
a.Close
End If
End Sub
Function PopulateTestNames()
Set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "http://hwps-alms-prv02:8080/qcbin"
tdc.Login "USER_NAME", "PASSWORD"
tdc.Connect "MY_DOMAIN", "My_Project"
Set TreeMgr = tdc.TreeManager
Set oRoot = TreeMgr.TreeRoot("Subject")
Set folder = oRoot.FindChildNode("MainScripts") 'updates spreadsheet with all tests within mainscripts
SubjectPath = folder.Path
Set TestFact = tdc.TestFactory
Set aTestFilter = TestFact.Filter
aTestFilter.Filter("TS_SUBJECT") = "^" & SubjectPath & "^" 'selects all the subfolders, too
aTestFilter.Order("TS_SUBJECT") = 1 '1st order is the subject
aTestFilter.Order("TS_NAME") = 2 '2nd order is test name
Set aTestList = aTestFilter.NewList
Set sh = ThisWorkbook.Sheets("Test List")
c = 1
For Each aTest In aTestList
Set aCell = sh.Cells(c, 1)
thePath = aTest.Field("TS_SUBJECT").Path
theName = aTest.Name
fullPath = "[ALM] " & thePath & "\" & theName
aCell.Value = fullPath ' populate cell with full path
c = c + 1
Next
End Function