Here's some of my code that I use to achieve this. It's hopefully enough to give you a bit of a head start.
I use a .vbs file, executed by wscript passing command line arguments to "sync" execution evidence from external tools (currently Maven and soapUI .. but expanding!) to ALM (11.5) and QC (10).
Once you've connected and authenticated, there are a couple of things you need to think about.
1. How do I find my Test Instance?
2. Do I add my attachment to the instance, or to a run?
3. If I'm adding to a run, do I need to create it?
I pass in the test name and use TestFactory.Filter to get the test id. I use the ID later on, to find the Test Instance. You may wish to use a different mechanism.
I'm happy to grab the first match.
<-- snip LOTS of declarations -->
Set QC = CreateObject("TDApiOle80.TDConnection")
<-- snip all of the initialisation and error handling -->
Set TestFactory = QC.TestFactory
Set TestFilter = TestFactory.Filter
TestFilter.Filter("TS_NAME") = "" & qcTestName & ""
Set TestList = TestFilter.NewList()
If TestList.Count > 0 Then
test_id = TestList.Item(1).ID
WScript.Echo "Could not find specified test (" & qcTestName & ")"
Set QC = Nothing
I pass in the Test Lab path and Test Set Name.
Now we have found the correct TEST SET, we can find our TEST INSTANCE by filtering.
<-- snip a few lines of code that crawl down the Test Lab Tree from ROOT creating any missing folders -->
Set TestLabTree = QC.TestSetTreeManager
Set TSFolder = TestLabTree.NodeByPath("" & path & "")
Set TestSetList = TSFolder.FindTestSets(TestSetName)
' BEWARE: FindTestSets does a pattern match, which can cause runs to be added to the wrong set.
' We need to loop through each match to find the right one.
<-- snip the loop/searching code -->
<-- snip a few lines of code that create the Test Set if it doesn't already exist-->
Set tSet = TestSetList.Item(searchindex)
I'm happy to grab the first match in the set.
Set TSTFact = tSet.TSTestFactory
Set TSTFilter = TSTFact.Filter
TSTFilter.Filter("TC_TEST_ID") = test_id
Set TestInstanceList = TSTFilter.NewList()
<-- snip a few lines of code that create the Test Instance if it doesn't already exist-->
Set TestInstance = TestInstanceList.Item(1)
2. I would always add the attachment to a run. If you want to add it to an Instance, then you can do this here via TestInstance.Attachments
3. If you change TestInstance.Status, then ALM will automatically create a RUN for you, in which case you'll need to identify it and then modify it, otherwise you'll have to create a new run.
Set RunFact = TestInstance.RunFactory
<-- snip A LOT of code that deals with automatic run creation and Test Instance properties -->
' here is how to create a Run
Set NewRun = RunFact.AddItem(Null)
NewRun.Status = qcResult
NewRun.Name = "Generated " & RunDate
NewRun.Field("RN_TESTER_NAME") = qcRunUserName
NewRun.Field("RN_HOST") = HostName
' here is how to add an attachment
Set AttachFact = NewRun.Attachments
Set NewAttach = AttachFact.AddItem(Null)
NewAttach.FileName = "C:\my\attachment\is\here.doc"
NewAttach.Type = 1 'TDATT_FILE