QC OTA - Test Plan - 2

- Find Test in Test Plan
- Return a SubjectNode object for a given path in the Test Plan

Function TestPlanFindTest(ByVal strTestName As String, ByVal strFolderToSearchPath As String, ByVal SearchChildFolders As Boolean, Optional ByVal strTestType As String, Optional blnSilentMode As Boolean) As Test
   
    Dim oParentNode As SubjectNode
    Dim SubjectNodeList As List
    Dim oSubjectNode As SubjectNode
    Dim intMatchCount As Integer: intMatchCount = 0
    Dim TestFact As TestFactory
    Dim oReturnValue As Test
    Dim TestFilter As TDFilter
    Dim TestList As List
    Dim oTest As Test
    Dim blnTypedMatched As Boolean: blnTypedMatched = True
   
    Set oParentNode = TestPlanGetSubjectNode(strFolderToSearchPath)
    Set TestFact = tdc.TestFactory
   
    'If there was an error getting the parent node then exit
    If (oParentNode Is Nothing) Then
        Set TestPlanFindTest = Nothing
        Exit Function
    End If

    'See if the parent folder has any tests that match the name we are looking for
    Set TestFilter = TestFact.Filter
    TestFilter.Filter("TS_SUBJECT") = Chr(34) & oParentNode.Path & Chr(34)
    Set TestList = TestFact.NewList(TestFilter.Text)
    For Each oTest In TestList
        'Debug.Print "Test Name='" & oTest.Name & "' Test Type=" & oTest.Type
        If (UCase(oTest.Name) = UCase(strTestName)) Then
            'See if we should match the type - by default it is set to matched (true)
            If (strTestType) <> "" Then
                If (oTest.Type = strTestType) Then
                    blnTypedMatched = True
                Else
                    blnTypedMatched = False
                End If
            End If
           
            If blnTypedMatched Then
                intMatchCount = intMatchCount + 1
                Set oReturnValue = oTest
            End If
        End If
    Next
   
    'Now check to see if we wanted to search child folders? If so search them
    If SearchChildFolders Then
        'Get all the child folders of the parent folder
        Set SubjectNodeList = oParentNode.FindChildren("", False, "")
        If Not (SubjectNodeList Is Nothing) Then
            For Each oSubjectNode In SubjectNodeList
                'Debug.Print oSubjectNode.Path
                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
                    If (UCase(oTest.Name) = UCase(strTestName)) Then
                        'See if we should match the type - by default it is set to matched (true)
                        If (strTestType) <> "" Then
                            If (oTest.Type = strTestType) Then
                                blnTypedMatched = True
                            Else
                                blnTypedMatched = False
                            End If
                        End If
                       
                        If blnTypedMatched Then
                            intMatchCount = intMatchCount + 1
                            Set oReturnValue = oTest
                        End If
                    End If
                Next
            Next
        End If
    End If
   
   
    'Clean Up
    Set oParentNode = Nothing
    Set SubjectNodeList = Nothing
    Set oSubjectNode = Nothing
    Set TestFact = Nothing
    Set TestFilter = Nothing
    Set TestList = Nothing
    Set oTest = Nothing
   
   
    'Now return a value
    Select Case intMatchCount
        Case 0
            If Not blnSilentMode Then
                MsgBox "Error: The Test could not be found with the parameters: " & Chr(10) & _
                    "Test Name:" & strTestName & Chr(10) & _
                    "Parent Folder Path:" & strFolderToSearchPath & Chr(10) & _
                    "Test Type:" & strTestType & Chr(10) & _
                    "Search child folders?:" & SearchChildFolders, vbExclamation + vbOKOnly, "TestPlanFindTest"
            End If
            Set TestPlanFindTest = Nothing
        Case 1
            Set TestPlanFindTest = oReturnValue
        Case Else
            If Not blnSilentMode Then
                MsgBox "Error: A total of " & intMatchCount & " tests were found with the following criteria: " & Chr(10) & _
                    "Test Name:" & strTestName & Chr(10) & _
                    "Parent Folder Path:" & strFolderToSearchPath & Chr(10) & _
                    "Test Type:" & strTestType & Chr(10) & _
                    "Search child folders?:" & SearchChildFolders, vbExclamation + vbOKOnly, "TestPlanFindTest"
            End If
            Set TestPlanFindTest = Nothing
    End Select

End Function
------------------------------------------------------------------------------------------------
Function TestPlanGetSubjectNode(ByVal strPath As String) As SubjectNode
    Dim TreeMgr As TreeManager
    Dim SubjRoot As SubjectNode
    Dim SubjectNodeList As List
    Dim oSubjectNode As SubjectNode
   
   
    Set TreeMgr = tdc.TreeManager
    Set SubjRoot = TreeMgr.TreeRoot("Subject")
   
    'Trim any trailing \
    If Right(strPath, 1) = "\" Then strPath = Left(strPath, Len(strPath) - 1)
   
    If UCase(strPath) = "SUBJECT" Then
        Set TestPlanGetSubjectNode = SubjRoot
        Set TreeMgr = Nothing
        Set SubjRoot = Nothing
        Exit Function
    End If
   
   
    Set SubjectNodeList = SubjRoot.FindChildren("", False, "")
   
    For Each oSubjectNode In SubjectNodeList
        If UCase(oSubjectNode.Path) = UCase(strPath) Then
            Set TestPlanGetSubjectNode = oSubjectNode
            Exit Function
        End If
    Next
   
    MsgBox "Test Plan path not found: " & strPath, vbExclamation + vbOKOnly, "TestPlanGetSubjectNode Error"
    Set TestPlanGetSubjectNode = Nothing
    Set TreeMgr = Nothing
    Set SubjRoot = Nothing
    Set SubjectNodeList = Nothing
    Set oSubjectNode = Nothing
End Function
---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?