Monday, July 11, 2016

Update Test Steps in TestLab ALM (QC)

' Read data from excel add to dictionary
Set objTestRunResult = CreateObject("Scripting.Dictionary")

objTestRunResult.Add "Step 1"Array("Passed""Desc1""Expected1""Actual1")
objTestRunResult.Add "Step 2"Array("Passed""Desc2""Expected2""Actual2")
objTestRunResult.Add "Step 3"Array("Failed""Desc3""Expected3""Actual3")

'Input - TestSet Path
sFolder = "Root\Automation\Test"
sTestSetName = "test"
strTestName = "test"

' ALM Connection
    Dim oTestDirObj
    Dim sQCServer
    sQCServer = "http://XXXXX/qcbin"
    sQcUser = "XXXX"
    sQcPassword = "xxxxx"
    sQcDomain = "xxxx"
    sQcProject = "xxxxx"

'Define the connection object
    Set oTestDirObj = CreateObject("TDApiOle80.TDConnection")
    oTestDirObj.InitConnectionEx sQCServer
    oTestDirObj.Login sQcUser, sQcPassword
    oTestDirObj.Connect sQcDomain, sQcProject

'Navigate to the folder containing the test set.
'    Set oTestDirObj = QCUtil.QCConnection
    Set oTstFact = oTestDirObj.TestSetFactory
    Set oTstMgr = oTestDirObj.TestSetTreeManager
    Set oTestFolder = oTstMgr.NodeByPath(sFolder)

'selecting a particular testset in the folder
    set oTstSetFilter = oTestFolder.TestSetFactory.Filter
    set oTstList = oTstSetFilter.NewList()
    For i = 1 To oTstList.Count
        If Trim(oTstList.Item(i).Name) = Trim(sTestSetName)Then
            Set oListTstSet = oTstList.Item(i)
            Exit For
        Else
'            MsgBox "Testset not found"    
        End If
    Next

    Set oListTstSetFilter = oListTstSet.TSTestFactory.Filter
    Set oTestCase = oListTstSetFilter.NewList()
    For testcasenum = 1 To oTestCase.count
        If oTestCase.Item(testcasenum).Name = "[1]"& strTestName Then ' Test case Name            
            set oTstRunObj = oTestCase(testcasenum).RunFactory         
            strRun_Name = "Run_" & Year(Now()) & "_" & Month(Now())& "_" & Day(Now()) & "-" & Hour(Now()) & "_" &Minute(Now()) & "_" & Second(Now())
            Set objTestRun = oTstRunObj.AddItem(CStr(strRun_Name))
            objTestRun.CopyDesignSteps
            objTestRun.Post
        
            Set objTsTestStepFactory = objTestRun.StepFactory
       
            Dim newStep, iStep
            Dim objSteps
            strfailflg = False
         
            objSteps = objTestRunResult.Items         
            For iStep = 1 To objTestRunResult.Count Step 1             
                Set myStep = objTsTestStepFactory.NewList("")
                myStep.Item(iStep).Field("ST_STATUS") = objSteps(iStep-1)(0' "Passed"
                'myStep.Item(iStep).Field("ST_DESCRIPTION") = objSteps(iStep-1)(1)
               ' myStep.Item(iStep).Field("ST_EXPECTED") = objSteps(iStep-1)(2)
                myStep.Item(iStep).Field("ST_ACTUAL") = objSteps(iStep-1)(3)' "Actual Value"
                myStep.Item(iStep).Post                 
                'Check for Failed
                If objSteps(iStep-1)(0) = "Failed" Then
                    strfailflg = True
                End If
            Next
            ' Update Final Result
            If strfailflg Then
                objTestRun.Status = "Failed" ' Final Result
            Else
                objTestRun.Status = "Passed" ' Final Result
            End If
            objTestRun.Post     
        End If             
    Next
         

No comments:

Post a Comment