QC OTA - Test Lab



Here are some amazing functions that can be reused wrt QC OTA for Test Lab module:
- Create Test Set
- Add tests to Test Set
- Create the supplied directory structure in the test lab
- Create a test set underneath a given parent
- Return a test set if it exists
- Returns a testsetfolder for the given path
Public Function TestLabCreateTestSet(strFolderPath As String, strTestSetName As String, ByRef CreatedTestSet As TestSet)
    Dim tstSetFolder As TestSetFolder
    Dim testSetFolderF As TestSetTreeManager
    Dim TestSetF As TestSetFactory
    Dim testSet1 As TestSet
    Dim oTestSet As TestSet
   
   
    'Does the test set already exist? If so return it
    Set oTestSet = TestLabGetTestSet(strFolderPath, strTestSetName)
    If Not (oTestSet Is Nothing) Then
        'MsgBox "Test Set Already Exists: " & strFolderPath & "\" & strTestSetName
        Set CreatedTestSet = oTestSet
        Exit Function
    End If
   
   
    Set testSetFolderF = tdc.TestSetTreeManager
    Set tstSetFolder = TestLabGetFolderByPath(strFolderPath)
   
    Set TestSetF = tstSetFolder.TestSetFactory
    Set testSet1 = TestSetF.AddItem(Null)
    testSet1.Name = strTestSetName
    testSet1.Status = "Open"
    testSet1.Field("CY_USER_01") = "Reviewed"
    'testSet1.
    testSet1.Post
   
   
    If Err = 0 Then
        TestLabCreateTestSet = True
        Set CreatedTestSet = testSet1
    Else
        MsgBox Err.Description
        TestLabCreateTestSet = False
    End If
End Function
----------------------------------------------------------
Public Function TestLabAddTestToTestSet(ByVal objTestSet As TestSet, ByVal objTest As Test, ByRef objTestInTestSetObj) As Boolean
    Dim testInstanceF As TSTestFactory
   
    On Error GoTo ErrTrap
    'Get or create a test instance from the factory of the new test set
    Set testInstanceF = objTestSet.TSTestFactory
    Set objTestInTestSetObj = testInstanceF.AddItem(objTest.ID)
   
    objTestInTestSetObj.Status = "No Run"
    objTestInTestSetObj.Post
   
    TestLabAddTestToTestSet = True
    Exit Function
   
ErrTrap:
    MsgBox Err.Description, vbCritical, "TestLabAddTestToTestSet"
    TestLabAddTestToTestSet = False
End Function

------------------------------------------------------------------------
Public Sub TestLabCreateDirectoryStructure(ByVal strPath As String)
   
    Dim arrPath
    Dim n As Integer
    Dim strCurrentPath
    Dim strLastParent
    Dim strLeft
   
    'If they have supplied "root\" in the start of the string, strip this out
    If Len(strPath) > 5 Then
        strLeft = Left(strPath, 5)
        If UCase(strLeft) = "ROOT\" Then
            strPath = Right(strPath, Len(strPath) - 5)
        End If
    End If
   
    arrPath = Split(strPath, "\")
   
    strCurrentPath = "Root"
    strLastParent = "Root"
   
    'Create the directory
    For n = 0 To UBound(arrPath)
        'Update the current path value
        strCurrentPath = strCurrentPath & "\" & arrPath(n)
       
        'If the folder does not exist, create it
        If Not TestLabDoesFolderExist(strCurrentPath) Then
            Call TestLabCreateTestSetFolder(strLastParent, arrPath(n))
        End If
        'Update last parent
        strLastParent = strLastParent & "\" & arrPath(n)
    Next n
End Sub

----------------------------------------------------------------------
Public Function TestLabCreateTestSetFolder(ByVal strParentPath As String, ByVal strFolderName As String)
   
    If strFolderName = "" Then
        TestLabCreateTestSetFolder = False
        Exit Function
    End If
   
    'Add test set folder.
    Dim TestSetF As TestSetTreeManager
    Dim objParent As TestSetFolder
    Dim folder As TestSetFolder
   
       
    Set TestSetF = tdc.TestSetTreeManager
    Set objParent = TestLabGetFolderByPath(strParentPath)
    Set folder = objParent.AddNode(strFolderName)
    folder.Post
   
    If Err = 0 Then
        TestLabCreateTestSetFolder = True
    Else
        MsgBox Err.Description
        TestLabCreateTestSetFolder = False
    End If
       
End Function

-----------------------------------------------------------------------

Public Function TestLabDoesFolderExist(ByVal strPath As String)
   
    On Error Resume Next
    Dim tstSetFolder As TestSetFolder
    Dim testSetFolderF As TestSetTreeManager
    Dim objCurrentFolder As TestSetFolder
    Dim lastFolder As TestSetFolder
    Dim n
    Dim arrPath
   
    Set testSetFolderF = tdc.TestSetTreeManager
    Set lastFolder = testSetFolderF.Root
   
    'For some reason, NodeByPath is not working, but we can check it by getting the children
    arrPath = Split(strPath, "\")
   
    If UBound(arrPath) > 0 Then
        For n = 1 To UBound(arrPath)
            Set objCurrentFolder = Nothing
            Set objCurrentFolder = lastFolder.FindChildNode(arrPath(n))
            Set lastFolder = objCurrentFolder
        Next n
    End If
   
    If (objCurrentFolder Is Nothing) Then
        TestLabDoesFolderExist = False
    Else
        TestLabDoesFolderExist = True
    End If
   
   
    On Error GoTo 0
End Function

-------------------------------------------------------------
Public Function TestLabGetFolderByPath(strPath As String) As TestSetFolder
    Dim objTestTreeManager As TestSetTreeManager
    Dim objCurrentFolder As TestSetFolder
    Dim arrPath
    Dim n
   
    'Get the tree manager
    Set objTestTreeManager = tdc.TestSetTreeManager
    'Get the root object - we will search the children of this
    Set objCurrentFolder = objTestTreeManager.Root
   
    'Split out the path
    arrPath = Split(strPath, "\")
   
    'We already have the root as an object so skip element 0
    If UBound(arrPath) > 0 Then
        'Loop through the path, getting each folder as a child
        For n = 1 To UBound(arrPath)
            Set objCurrentFolder = objCurrentFolder.FindChildNode(arrPath(n))
        Next n
    End If
   
    Set TestLabGetFolderByPath = objCurrentFolder
End Function

--------------------------------------------------------------------
Public Function TestLabGetTestSet(ByVal strFolderPath As String, ByVal strTestSetName As String) As TestSet
   
    Dim tsFilter As TDFilter
    Dim tsList As IList
    Dim oTestSetFolder As TestSetFolder
    Dim aTestSet As TestSet
    Dim TSetFact As TestSetFactory
    Dim arrFolderPath() As String
   
       
    'Get the folder
    Set oTestSetFolder = TestLabGetFolderByPath(strFolderPath)
    Set TSetFact = tdc.TestSetFactory
   
    'When looking for the test sets we can use the "CY_FOLDER_ID" property. This contains the name of the parent folder
    'So we just need to extract what the name of the parent folder is
    arrFolderPath = Split(strFolderPath, "\") 'break up the paths so the parent folder is in the upper bound
    'Create the filter:
    Set tsFilter = TSetFact.Filter
    'Get a list of the test sets - this will contain all of the child test cases
    Set tsList = oTestSetFolder.FindTestSets("", False, tsFilter.Text)
   
    If Not (tsList Is Nothing) Then
        For Each aTestSet In tsList
            'Does this test set name and path match what we are looking for?
            If (UCase(aTestSet.TestSetFolder.Path) = UCase(strFolderPath)) And (UCase(aTestSet.Name) = UCase(strTestSetName)) Then
                'Return value & cleanup
                Set TestLabGetTestSet = aTestSet
                Set tsList = Nothing
                Set tsFilter = Nothing
                Set TSetFact = Nothing
                Set oTestSetFolder = Nothing
                Exit Function
            End If
        Next aTestSet
    End If

    'no matches found, return nothing
    Set TestLabGetTestSet = Nothing
    Set tsList = Nothing
    Set tsFilter = Nothing
    Set TSetFact = Nothing
    Set oTestSetFolder = Nothing
End Function


Source: http://automationandtesting.blogspot.co.uk/2011/11/treeview-for-quality-center-test-plan.html

Comments

  1. Anonymous23/5/12

    Hi Aditya,

    I would like get the count of test sets in subfolders.
    EX: root\test where test is main folder after root. When test has two sub folders named test1 and test2 and each having 5 test sets , how can I get the count of test sets in these sub folders.

    Thanks
    Praveen

    ReplyDelete
  2. This should do what you are looking for:
    http://stackoverflow.com/questions/4212316/quality-center-ota-api-return-just-the-first-level-of-child-testsets-in-a-tests

    Let me know if you are facing trouble.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi Aditya,

    Very good post.
    I am trying this code, facing issue at 'TestSetTreeManager'.

    My code is:
    Set tdc= CreateObject("TDApiOle80.TDConnection")
    ------------Aithenticating Successfully...
    ------logged into the project--------------
    //Now I am trying to get TestSetTreeManager
    Set objTestTreeManager = tdc.TestSetTreeManager //Here I am getting error "User Defined Type not defined".

    Can you please let me know if i need to do anything else in my script.
    I am very new to VB Script. Your help in resolving this issue is appreciated.

    Thanks,
    Lenina

    ReplyDelete
    Replies
    1. Hi Lenina,

      The "TestSetTreeManager" is a child method of the TDConnection object. The code that is presented here is in vba and not vbscript therefore you would notice a line that says "Dim objTestTreeManager As TestSetTreeManager"
      If you want to do the same in vbscript then you need to create it under a particular folder under the testlab tree :

      Set objTestTreeManager = tdc.TestSetTreeManager.NodeByPath("Root\T​BD\TEST")

      Best Regards,
      Ady

      "Besides black art, there is only automation"
      Technology Specific Guide For QTP - My new Book on QTP

      Delete
  5. Anonymous15/9/12

    Hi Adiya,

    I was trying to pull the reports from QC for the test cases executed based on the TestSet folder. For example:

    I have following root folder for the test lab
    root\application1\release 1\SIT


    Within that i have multiple folders

    \folder1 (may have sub folders)
    \folder 2 (may have sub fodlers)

    And each end level folders may have multiple test sets.

    I was wondering if you have a code which takes the test lab root folder say in my case "root\application1\release 1\SIT" from the test lab and gives me the test name and status for each of the test cases across the test sets and test set folders within the root folder.

    Appreciate your help.

    -Mahavir

    ReplyDelete
  6. Hi, can any one explain how to attach any excel report to qc using OTA util ?

    ReplyDelete
  7. Vini - This might help http://go-gaga-over-testing.blogspot.in/2012/10/important-reusable-functions-qtp.html , let me know if you find any success..

    Best Regards,
    Ady

    ReplyDelete
  8. Anonymous12/11/12

    Hi aditya ,

    This satish from Chennai , i have a query regarding Automation QC , my requirement to pull all the property of the testcase from QC using vbscript (Need all testfield)

    ReplyDelete
  9. Hi Aditya,

    I need to create a status report for all test cases in particular folder. Folder path is like Root\Dry Run\System Integration, inside system integration there are multiple folders and each folder contains multiple test sets.
    Can you please help how can i generate the report.
    Structure is like:
    Root\Dry Run\System Integration\Test1 - Test1 contains multiple folders name: Test11, Test12, Test13 and each folder contains multiple test sets

    ReplyDelete
  10. what value i need to pass in the ByRef CreatedTestSet As TestSet in the first function while creating the testset.

    ReplyDelete
  11. how to set the test set details tab fields using OTA? like designer status and all

    ReplyDelete
  12. Hi Aditya,
    Great article exactly what i was looking,
    What I am trying to do is to create test lab using your function "TestLabAddTestToTestSet"

    Can you please tell me what i need to pass in objTest.ID?? Is it the test id of the test case in test plan tree?

    I did this and I am getting error test not found.
    Thanks
    yatharth

    ReplyDelete
  13. Anonymous18/5/14

    I have baselined some tests in ALM 11.00.
    Created a "Pinned to Baseline" test set.
    Trying to run those baselined tests, via QTP, from the "pinned to baseline" test set.

    At runtime I want to check if a test is “pinned to baseline” from QC (will be using Test.VCS properties for this) but not sure how to use that to grab it’s resources (parameters,attachments etc) of the same baseline?
    The DownloadResource functionality only appears to get the latest and not a specified version.

    Any help would be appreciated.

    Thanks,
    Shaun

    ReplyDelete
  14. Anonymous21/5/15

    Hi Aditya, I found your blog whilst looking for something else. This is code I posted a while ago, I'm happy that it's being used but it would be nice if you put a reference to my blog where it was originally from.

    http://automationandtesting.blogspot.co.uk/

    Regards

    David Hartley

    ReplyDelete
    Replies
    1. Hi David,

      I am extremely sorry I generally post a reference if I pick anything from any blog(with permission). This was shared by a friend I shall go ahead and add a reference to your blog. Please let me know if you want me to remove this post and I wouldn't mind that.

      Best Regards,
      Ady

      Delete
    2. Anonymous26/5/15

      No problem Ady, please keep this page active as it will help everyone else and just reference my blog. This is the original page: http://automationandtesting.blogspot.co.uk/2011/11/treeview-for-quality-center-test-plan.html

      Happy for you to delete this thread from the page.

      Best wishes

      Dave

      Delete
    3. Thanks David,
      More than happy to let this thread stay so people can redirect while they read comments.
      I will anyway add a reference to your page.

      Cheers,
      Ady

      Delete
  15. Hi
    How do I get test runs from the run table?
    Please help

    ReplyDelete
    Replies
    1. You would want to have a look at this http://automationandtesting.blogspot.co.uk/2011/11/treeview-for-quality-center-test-plan.html

      Delete
  16. thanks for this informative blog posting.. keep posting, keep updating and keep blogging..
    pathology lab in janakpuri

    ReplyDelete
  17. In 2003 I was using the ALM AOM when it was TD and QC. I have not looked at it since then. I'm trying to find out how to append some text into the pass/fail area of a test run. It says Description, expected, actual. After the run is complete I wish to add some more information to this field in the Test Lab. I can use some assistance.

    ReplyDelete
  18. Anonymous5/3/24

    I need to fetch the the parameters values are which are present in execution settings for each iteration in test lab using OTA. Can anyone please help

    ReplyDelete

Post a Comment

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?