我运行以下代码,但ALM中未显示任何内容:

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

第二行的AddItem方法不断询问“对象ItemData”,但我不知道那是什么。 HP的文档太差,以至于没有任何解释。有人知道如何以编程方式使用C#在HP ALM中为测试运行添加文件附件吗?

最佳答案

经过大量的痛苦和研究,我找到了答案。我确信还有其他方法可以更有效地完成此任务,但是由于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();
                    }
                }
            }
        }
    }
}

关于c# - 如何通过C#在ALM OTA中向测试集添加附件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28906449/

10-08 21:50