2015-03-06 6 views
6

uruchomić poniższy kod, ale nic nie pokazuje się w ALM:Jak dodać załącznik do zestawu testów w ALM OTA za pomocą C#?

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

Sposób AddItem w drugim wierszu wciąż prosząc o „obiekt itemData”, ale nie mam pojęcia co to jest dokładnie. HP ma tak słabą dokumentację, że tak naprawdę nic nie wyjaśnia tego. Czy ktoś wie jak programowo używać C# dodać załącznik pliku do testu uruchamianego w HP ALM?

+0

Anyone? Bueller? Bueller? Bueller? –

Odpowiedz

4

Po wielkim bólem i badań znalazłem odpowiedź. Jestem pewien, że istnieją inne sposoby na osiągnięcie tego, które są bardziej wydajne, ale ponieważ dokumentacja HP ​​jest najgorsza na świecie, jest to najlepsze, co mogę wymyślić. Jeśli ktokolwiek ma lepszy sposób, chciałbym go zobaczyć, więc proszę go opublikować!

Mam nadzieję, że to pomoże!

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's 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(); 
        } 
       } 
      } 
     } 
    } 
} 
+1

Dla typu zerowego Java jest: new Variant (Variant.Type.VT_NULL) nadzieję, że to pomoże komuś :) –

1

Zrobiłem coś podobnego, ale w Pythonie i przeciwko próbnym krokom, więc nawet jeśli nie mam kodu, można skopiować & go wkleić, to może skierować cię we właściwym kierunku.

Zamiast nazywać:

attachmentFactory.AddItem(filename) 

Wywołanie funkcji bez parametrów (lub null paramer, nie mogę powiedzieć, ponieważ nigdy nie używałem API OTA z C#):

file = attachmentFactory.AddItem() 

teraz przypisz plik do elementu załącznika, a pozostałe jego właściwości:

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

Typ określa lokalny plik, a nie adres URL.

+1

Stary, wielkie dzięki! Potrzebowałem tego !!! – BUInvent

0

Brak cennych informacji w Internecie! Po pewnym kopania w sprawie dokumentacji OTA Znalazłem to:

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); 

rzeczywiście, był w formie skryptu VB, ale udało mi się przekształcić w języku C#. OTA referencyjny:

'----------------------------------------- 
'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

Próbowałem powyższego kodu w C#, ale nie dołącza pliku do uruchomienia testu. Czy to działa dla ciebie? –

1

Jeśli ktoś zastanawia się, jak to zrobić na module wymóg, oto kod:

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*"); 
Powiązane problemy