3

I've recently created a new recovery scenario which we want to add to all of our existing run scripts which number in the hundreds.

Unfortunately, setting it to be included in the default only works for new script creations and doesn't retrospectively add it to all existing scripts.

I've asked HP Support and they've advised you need to add it in each script in the test settings|recovery manually for each script. I've asked them to list it as a feature request for future releases so hopefully that will come to fruition and help people in the future.

What we wish to do now is create a function or script which we can list folders in quality center and go through all of the scripts within, updating them.

We've noticed however that checking out a script, editing it and checking it in during run time doesn't work as Quality Center seems to run all scripts in read-only.

Is there any other way to Add a recovery scenario and more importantly, save it to the script?

I've found that you can dynamically add recovery scenarios during run time however the issue with that is, recovery scenarios won't work in that same run and only in the next so the script would have to completely stop and start again every single time for every script.

Any help is appreciated. Thanks

2 Answers2

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
Barney
  • 1,851
  • 2
  • 19
  • 36
0

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
  • Should be easy to get the list of UFT tests from HP QC using OTA. I'll post the code tomorrow morning. – Barney Dec 08 '16 at 02:55
  • sorted out the log already. Trying to get the absolute paths for all tests within [ALM] Subject\Scripts\MainScripts\ and its subfolders – Jarrard Scott Dec 09 '16 at 00:00
  • updated my above answer with the code to dynamically build the HP ALM path and iterate over all the UFT Scripts. – Barney Dec 09 '16 at 03:00