Showing posts with label OTA API. Show all posts
Showing posts with label OTA API. Show all posts

Wednesday, 8 October 2014

HP ALM Workflow with AuditRecord and AuditProperty to retrieve defect history with old value and new value

HP ALM Workflow with AuditRecord and AuditProperty to retrieve defect history with old value and new value

Why this blog entry? 

I need a solution that allow me to retrieve the latest history changes on defect STATUS (old and new value). Unfortunately, I'm not able to get a quick solution from the net.

The Solution

 Set AuditRecordFactory = TDConnection.AuditRecordFactory
Set AuditRecordFactoryFilter = AuditRecordFactory.Filter
AuditRecordFactoryFilter.Filter("AU_ENTITY_TYPE") = "BUG"
AuditRecordFactoryFilter.Filter("AU_ENTITY_ID") = "10327" 'Defect ID'
AuditRecordFactoryFilter.Order("AU_TIME") = 1
AuditRecordFactoryFilter.OrderDirection("AU_TIME") = 1 'Sort the list in decending order
Set AuditRecordList = AuditRecordFactory.NewList(AuditRecordFactoryFilter.Text)

If AuditRecordList.Count < 10 Then
    For Each audit In AuditRecordList
 
       'Below line will retrieve changes made against Defect Status
       Set AuditPropertyFactoryFilter = audit.AuditPropertyFactory.Filter
       AuditPropertyFactoryFilter.Filter("AP_FIELD_NAME") = "BG_STATUS"
       AuditPropertyFactoryFilter.Filter("AP_ACTION_ID") = audit.ActionID 'This line is needed. Else, you will be retrieving all the records
     
       Set ChangeList = audit.AuditPropertyFactory.NewList(AuditPropertyFactoryFilter.Text)
   
       If ChangeList.Count = 1 Then
           For Each Change In ChangeList
               MsgBox "User [" & audit.UserName & "] performed [" & audit.Action & "] at [" & audit.Time & "] with detail:"
               MsgBox "FieldName: [" & Change.FieldName & "] @ OldValue: [" & Change.OldValue & "] @ NewValue: [" & Change.NewValue & "]"
           Next
         
           Exit For
       ElseIf ChangeList.Count > 1 Then
           MsgBox "Warning!, Audit Property has more than 1 changes on BG_STATUS. Changes count is " & ChangeList.Count
       End If
    Next
Else
    MsgBox "Audit Record Count: " & AuditRecordList.Count
End If

Set tdConnection = Nothing

Happy testing!

Thursday, 16 May 2013

Extend HP TestResultsDeletionTool.exe for more advanced test result clean up customization by using OTA API with VB scripting


Extend the TestResultsDeletionTool more for advanced deletion customization such as test plan folder/sub folder deletion, test result count constraint deletion etc by using OTA API with VB scripting


Problem

Test executing via Quality Center, 250 testsets, 400 manual scripts which run bi-weekly, and 1000 automated scripts which run nightly leads to tons of test results (since 2010) has been generated and this has indirectly consumes up to GBs of disk spaces in the running environment.

HP's TestResultsDeletionTool can be use to clean up the mess, however I wish to do something more advances like
- Batch cleaning
- Test Plan folder/sub folder cleaning
- Clean up the test result if it has more than 100 counts (to keep results for low frequent execution test cases)

Solution

By using OTA API with VB scripting. VB script can be downloaded by clicking on vbscript.

As TestResultsDeletionTool is using test case as the primary source to delete its run history, hence we need a way to navigate from [Test Case -> Test Set (Test Lab) -> Test Instance -> Run History] to find its way for the clean up

Explanation 1: Below codes is needed to do a cross filter from Test Set to Test Case in order to list out all Test Set that has an instance of Test Case being assigned to.
'filter by test case idSet TestFilter = TestFact.FilterTestFilter.Filter("TS_TEST_ID") = Chr(34) & oTest.ID & Chr(34)            'setup to retrieve test set listSet TestSetFact = objTDConnection.TestSetFactorySet TestSetTreeManager = objTDConnection.TestSetTreeManagerSet TestSetFilter = TestSetFact.Filter            'Set cross filter to filter by test case idTestSetFilter.SetXFilter "TESTSET-TEST", True, TestFilter.Text
'retreive testset listSet TestSetList = TestSetFact.NewList(TestSetFilter.Text)
Explanation 2: Below code is needed to retrieve the Run History count from each test instance in each test of the selected Test Set
ForEach itemTestSet In TestSetList    'print("TestID[" & oTest.ID & "], TestSetName[" & itemTestSet.Name & "], TestSetID[" & itemTestSet.ID & "]")    strTestSetName = itemTestSet.Name    Set TSTestFact = itemTestSet.TSTestFactory    Set TestSetTestsList = TSTestFact.NewList("")    'print(TestSetTestsList.Count)    'Get the total count for the particular test case    'In case total count > 100 (as per define in variable), proceed with the deletion    'Else keep the record, as it is not regularly run                     ForEach testInstanceItem In TestSetTestsList          IfStrComp(testInstanceItem.TestID, oTest.ID, vbTextCompare)=0Then              Set runFactory = testInstanceItem.RunFactory              Set runFactoryList = runFactory.NewList("")              'print("TestSetName[" & itemTestSet.Name & "], TestID[" & testInstanceItem.TestID & "], Instances[" & testInstanceItem.Instance & "], runFactoryList.Count[" & runFactoryList.Count & "]" )              intTotalCount = intTotalCount + runFactoryList.Count          EndIf     NextNext
Explanation 3: Code to trigger TestResultsDeletionTool silently. TestResultsDeletionTool will only works if it is running from the QC Server machine. From observation, if you run from remote machine, nothing will be clean up. Please be aware

The VB script has to call from the machine where the QC
Set wcshell = WScript.CreateObject("WScript.Shell")'Call TestResultsDeletionTool.exestrExeTest = " -Test " & Chr(34) & "[QualityCenter] " & oSubjectNode.Path & "\" & oTest.Name & Chr(34)'print("Deleting test results for --> " & oSubjectNode.Path & "\" & strTestSetName)wcshell.Run strExeDefault & strExeTest, 1, True

Lesson learnt 

N/A

Happy testing!