How to add an application to a test suite in ALM OTA via C #?

I run the following code, but nothing is displayed in ALM:

AttachmentFactory attachmentFactory = (AttachmentFactory)tsTest.Attachments; TDAPIOLELib.Attachment attachment = (TDAPIOLELib.Attachment)attachmentFactory.AddItem("test"); attachment.Post(); 

The AddItem method in the second line continues to query for the “ItemData object”, but I have no idea what it is. HP has such poor documentation that it really doesn't explain anything. Does anyone know how to programmatically use C # add a file attachment to a test run in HP ALM?

+6
source share
4 answers

After much pain and research, I found the answer. I'm sure there are other ways to achieve this that are more effective, but since the HP documentation is the worst on the planet, this is the best I could think of. If anyone has a better way, I would LOVE to see it, so please post it!

Hope this helps!

 try { if (qcConn.Connected) { string testFolder = @"Root\YourFolder"; TestSetTreeManager tsTreeMgr = (TestSetTreeManager)qcConn.TestSetTreeManager; TestSetFolder tsFolder = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolder); AttachmentFactory attchFactory = (AttachmentFactory)tsFolder.Attachments; List tsList = tsFolder.FindTestSets("YourTestNameHere", false, null); foreach (TestSet ts in tsList) { TestSetFolder tstFolder = (TestSetFolder)ts.TestSetFolder; TSTestFactory tsTestFactory = (TSTestFactory)ts.TSTestFactory; List mylist = tsTestFactory.NewList(""); foreach (TSTest tsTest in mylist) { RunFactory runFactory = (RunFactory)tsTest.RunFactory; Run run = (Run)runFactory.AddItem("NameYouWantDisplayedInALMRuns"); run.CopyDesignSteps(); //runResult just tells me if overall my test run passes or fails - it not built in. It was my way of tracking things though the code. if(runResult) run.Status = "Failed"; else run.Status = "Passed"; run.Post(); //Code to attach an actual file to the test run. AttachmentFactory attachmentFactory = (AttachmentFactory)run.Attachments; TDAPIOLELib.Attachment attachment = (TDAPIOLELib.Attachment)attachmentFactory.AddItem(System.DBNull.Value); attachment.Description = "Attach via c#"; attachment.Type = 1; attachment.FileName = "C:\\Program Files\\ApplicationName\\demoAttach.txt"; attachment.Post(); //Code to attach a URL to the test run AttachmentFactory attachmentFactory = (AttachmentFactory)run.Attachments; TDAPIOLELib.Attachment attachment = (TDAPIOLELib.Attachment)attachmentFactory.AddItem(System.DBNull.Value); //Yes, set the description and FileName to the URL. attachment.Description = "http://www.google.com"; attachment.Type = 2; attachment.FileName = "http://www.google.com"; attachment.Post(); //If your testset has multiple steps and you want to update //them to pass or fail StepFactory rsFactory = (StepFactory)run.StepFactory; dynamic rdata_stepList = rsFactory.NewList(""); var rstepList = (TDAPIOLELib.List)rdata_stepList; foreach (dynamic rstep in rstepList) { if (SomeConditionFailed) rstep.Status = "Failed"; else rstep.Status = "Passed"; rstep.Post(); } else { rstep.Status = "No Run"; rstep.Post(); } } } } } } 
+4
source

I did something similar, but in Python and against the test steps, so even if I don’t have code that you can copy and paste it, this may indicate the right direction.

Instead of calling:

 attachmentFactory.AddItem( filename ) 

Calling a function without parameters (or a null parameter, I can not say since I have never used the OTA API with C #):

 file = attachmentFactory.AddItem() 

Now assign the file to the binding element and the rest of its properties:

 file.Filename = "C:\\Users\\myUser\\just\\an\\example\\path" + fileName file.Description = "File description" file.Type=1 file.Post() 

The type indicates the local file, not the URL.

+1
source

If anyone is interested in how to do this on the requirements module, here is the code:

 Req req = Globals.Connection.ReqFactory.Item(*ID*)); VersionControl versionControl = ((IVersionedEntity)req).VC as VersionControl; versionControl.CheckOut(string.Empty); AttachmentFactory attFac = req.Attachments; Attachment att = (Attachment)attFac.AddItem(System.DBNull.Value); att.Description = "*Your description here"; att.Type = (int)TDAPI_ATTACH_TYPE.TDATT_FILE; //for URL, change here att.FileName = "*Your path including filename here*"; att.Post(); versionControl.CheckIn("*Your check-in comment here*"); 
+1
source

No valuable information on the Internet! After some digging in the OTA documentation, I found this:

 AttachmentFactory attachmentFactory = (AttachmentFactory)TstTest.Attachments; TDAPIOLELib.Attachment attachment = (TDAPIOLELib.Attachment)attachmentFactory.AddItem("demoAttach.txt"); attachment.Description = "Bug Sample Attachment"; attachment.Post(); IExtendedStorage exStrg = attachment.AttachmentStorage; exStrg.ClientPath = "E:\\TestData"; exStrg.Save("demoAttach.txt", true); 

Actually, it was in the form of a VB script, but I managed to convert to C #. OTA Link:

  '----------------------------------------- 'Use Bug.Attachments to ' get the bug attachment factory. Set attachFact = bugObj.Attachments 'Add a new extended storage object,an attachment ' named SampleAttachment.txt. Set attachObj = attachFact.AddItem("SampleAttachment.txt") ' Modify the attachment description. attachObj.Description = "Bug Sample Attachment" ' Update the attachment record in the project database. attachObj.Post ' Get the bug attachment extended storage object. Set ExStrg = attachObj.AttachmentStorage 'Specify the location of the file to upload. ExStrg.ClientPath = "D:\temp\A" '----------------------------------------- 'Use IExtendedStorage.Save to ' upload the file. ExStrg.Save "SampleAttachment.txt", True 
0
source

Source: https://habr.com/ru/post/983443/


All Articles