Как добавить вложение в тестовый набор в ALM OTA через С#?

Я запускаю следующий код, но в ALM ничего не отображается:

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

Метод AddItem во второй строке продолжает запрашивать «object ItemData», но я понятия не имею, что это такое. У HP настолько плохая документация, что на самом деле ничего не объясняет. Кто-нибудь знает, как программно с помощью С# добавить вложение файла к тестовому запуску в HP ALM?


person James Franken    schedule 06.03.2015    source источник
comment
Кто угодно? Бьюллер? Бьюллер? Бьюллер?   -  person James Franken    schedule 06.03.2015


Ответы (4)


После долгих мучений и исследований я нашел ответ. Я уверен, что есть другие способы сделать это, более эффективные, но, поскольку документация HP — худшая на планете, это лучшее, что я мог придумать. Если у кого-то есть лучший способ, я бы хотел увидеть его, поэтому, пожалуйста, опубликуйте его!

Надеюсь, это поможет!

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();
                    }
                }
            }
        }
    }
}
person James Franken    schedule 13.04.2015
comment
Для нулевого типа Java: новый вариант (Variant.Type.VT_NULL) надеюсь, что это кому-то поможет :) - person Jaroslav Štreit; 05.01.2017

Я сделал что-то подобное, но на Python и против шагов тестирования, поэтому, даже если у меня нет кода, вы можете скопировать и вставить его, это может указать вам правильное направление.

Вместо вызова:

attachmentFactory.AddItem( filename )

Вызовите функцию без параметров (или с нулевым параметром, не могу сказать, так как я никогда не использовал OTA API с C#):

file = attachmentFactory.AddItem()

Теперь назначьте файл элементу вложения и остальным его свойствам:

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

Тип указывает, что это локальный файл, а не URL-адрес.

person Leo    schedule 10.03.2015

Если кому-то интересно, как это сделать в модуле требований, вот код:

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*");
person Sebastian Augspurger    schedule 04.12.2017

Нет ценной информации в Интернете! Покопавшись в документации OTA, я нашел следующее:

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

на самом деле, был в виде скрипта VB, но мне удалось преобразовать его в C#. Ссылка ОТА:

   '-----------------------------------------
'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
person Ilie Daniel Stefan    schedule 12.03.2015
comment
Я попробовал ваш приведенный выше код на С#, но ему не удалось прикрепить файл к тестовому запуску. Это сработало для вас? - person James Franken; 16.03.2015