Tuesday 15 November 2011

Treeview for Quality Center Test Plan Using OTA & OTA Code Examples

I've uploaded a spreasheet containing examples of how to interact with the Quality Center OTA Test Plan and Test Lab Modules. 

You can download the spreadsheet here.

The examples attached to the buttons show a tree view selection dialog for the Test Plan. 


   



















The VBA Code Included also has examples for other OTA interactions as follows: 
Test Plan (QCTestPlanCommonFunctions)   
  • TestPlanCopyPasteTest - Uses OTA to copy a Test Case in the Test Plan.
  • TestPlanCreateFolderStructure - Uses OTA to create a folder structure in the Test Plan.  
  • TestPlanDoesPathExist - Uses OTA to return True / False if a directory / path exists in the Test Plan  
  • TestPlanDoesTestExist - Uses OTA to return True / False if a test exists in the Test Plan.   
  • TestPlanFindTest - Uses OTA to return a test for a given path and/or it's subfolders   
  • TestPlanGetSubjectNode - Uses OTA to return a Folder as a Subject Node object  
Test Lab(QCTestLabCommonFunctions)   
  • TestLabAddTestToTestSet - Uses OTA to add a test to a test set in the test lab.
  • TestLabCreateDirectoryStructure - Uses OTA to create a directory structure in the test lab  
  • TestLabCreateTestSet - Uses OTA to create a test set in a directory  
  • TestLabDoesFolderExist - Uses OTA to Returns True / False as to whether a folder exists  
  • TestLabGetFolderByPath - Uses OTA to returns a TestSetFolder object for a given path  
  • TestLabGetTestSet - Uses OTA to return a TestSet for a given path  
    
A couple of things:    
  • This code can sometimes fail after being run several times. I can't find the reason why, but usually closing Excel and reopening it fixes the issues.    
  • In your code, if you have a loop that creates a folder and then uses "TestLabGetFolderByPath" to find it, you may find it fails. Inserting a call to the function "RebootQCCon" resolves this.    

Friday 4 November 2011

Quality Center OTA: List all Tests in the Test Plan

The code below is a simple way to show all of the Folders and Tests in the Quality Center test plan. You could use this as a basis to develop a treeview of the testplan in another tool.

This code is designed to be run from Excel VBA, but you can easily adapt it for VBScript. It assumes that you have already connected to Quality Center which is represented by the "tdc" variable in the code.

This should help anyone having problems with the error "Field < Subject > requires a value from the corresponding list" - the answer to this problem is to encapsulate the subject with quotes - shown below with chr(34) wrapped around TS_Subject. It took me 2 hours to resolve that issue, no thanks to the OTA documentation!!

Sub ExploreTestPlan()
   
    Dim TreeMgr As TreeManager
    Dim SubjRoot As SubjectNode
    Dim TestFact As TestFactory
    Dim TestFilter As TDFilter
    Dim TestList As List
    Dim oTest As Test
    Dim SubjectNodeList As List
    Dim oSubjectNode As SubjectNode
   
    '*** make sure you have connected to QC with the tdc object ***


    Set TreeMgr = tdc.TreeManager
    Set SubjRoot = TreeMgr.TreeRoot("Subject")
    Set TestFact = tdc.TestFactory
    Set SubjectNodeList = SubjRoot.FindChildren("", False, "")
   
    For Each oSubjectNode In SubjectNodeList
        'Print out the subject path
        Debug.Print oSubjectNode.Path
       
        'Does this have any tests?
        Set TestFilter = TestFact.Filter
        TestFilter.Filter("TS_SUBJECT") = Chr(34) & oSubjectNode.Path & Chr(34)
        Set TestList = TestFact.NewList(TestFilter.Text)
        For Each oTest In TestList
            Debug.Print "Test Name='" & oTest.Name & "' Test Type=" & oTest.Type
        Next
       
    Next
   
End Sub