Thanks to Barney for the basis of the code. I've made a few amendments to suit our purposes better.
We have added
- check for whether a script is already checked out and adds it to a text log file.
- population of the spreadsheet with all test fullpaths within a folder/subfolder
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