Home » excel » Executing the test cases in alm from Excel by Test ID

Executing the test cases in alm from Excel by Test ID

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am trying to execute the test cases in QC ALM through an Excel macro. I am able to access the tests in testlist, but I am not able to find the particular test case I need to execute by its ID.

Below is the sample code I am using:

Set tsTreeMgr = tdConnection.testsettreemanager
Set tsFolder = tsTreeMgr.NodeByPath(nPath)
' --Search for the test set passed as an argument to the example code
Set tsList = tsFolder.FindTestSets("Test Set Name")

'------Accessing the Test Cases inside the Test SEt ----

Set theTestSet = tsList.Item(1)
For Each testsetfound In tsList
    Set tsFolder = testsetfound.TestSetFolder
    Set tsTestFactory = testsetfound.tsTestFactory
    Set tsTestList = tsTestFactory.NewList("")

    For Each tsTest In tsTestList
        MsgBox (tsTest.Name+","+ tsTest.ID)
        testrunname = "Test Case name from excel sheet"
        '----Accesssing the Run Factory ---
        Set RunFactory = tsTest.RunFactory
        Set obj_theRun = RunFactory.AddItem(CStr(testrunname))
        obj_theRun.Status = "Passed"
        obj_theRun.Post
    Next
Next

Any help to get TestCase in testset of testlab to execute would be great help.

How to&Answers:

I think you are looking for the TestId property of the TSTest object. So in your loop you could just test whether TestId matches the value from Excel:

If tsTest.TestId = testidfromexcel Then
    ' do something
End If

Or you can use a Filter to only get the TSTest instances from your Test Set that matches the respective test ID from Excel:

Set testSetFilter = tsTestFactory.Filter
testSetFilter.Filter("TC_TEST_ID") = testidfromexcel
Set tsTestList = testSetFilter.NewList()

Now your tsTestList should only contain test instances from the test with the ID from Excel.