/// <summary>
        /// Works when file path is on the desktop / c drive, but not on other drives....
        /// </summary>
        /// <param name="description"> Description of the attached file.</param>
        /// <param name="filePath"> Filepath to the file.</param>
        /// <returns>The server file name for the attachment.</returns>
        public string AddAttachment(string description, string filePath)
        {
            try
            {
                AttachmentFactory attachmentFactory = this.TestRun.Attachments as AttachmentFactory;
                attachmentFactory.NewList(string.Empty);
                Attachment attachment = attachmentFactory.AddItem(DBNull.Value) as Attachment;
                attachment.Description = description;
                attachment.Type        = 1;
                attachment.FileName    = filePath;
                attachment.Post();
                attachment.Refresh();
                attachment.Save(false);

                // We set that this test case instance has an attachment.
                this.HasAttachment = true;
                return(attachment.ServerFileName);
            }
            catch (Exception e)
            {
                e.ToString();
                throw new CannotAddTestCaseAttachment(CannotAddTestCaseAttachment.ErrorMsg + $"({this.Name}) - {description} and {filePath}");
            }
        }
示例#2
0
        private static void ExportRequirements()
        {
            string server_url = ConfigurationManager.AppSettings["SERVER_URL"];
            string username   = ConfigurationManager.AppSettings["USER_NAME"];
            string password   = ConfigurationManager.AppSettings["PASSWORD"];
            string domain     = ConfigurationManager.AppSettings["DOMAIN"];
            string project    = ConfigurationManager.AppSettings["PROJECT"];

            string req_file = ConfigurationManager.AppSettings["REQUIREMENTS_FILE"];
            string att_file = ConfigurationManager.AppSettings["ATTACHMENTS_FILE"];
            string att_path = ConfigurationManager.AppSettings["ATTACHMENTS_PATH"];

            if (!Directory.Exists(att_path))
            {
                Directory.CreateDirectory(att_path);
            }

            TDConnection tdc = new TDConnection();

            tdc.InitConnectionEx(server_url);
            tdc.ConnectProjectEx(domain, project, username, password);

            Console.WriteLine("Connected to QC Server");

            ReqFactory req_factory = (ReqFactory)tdc.ReqFactory;
            TDFilter   req_filter  = (TDFilter)req_factory.Filter;


            /**
             *  Set your own filters for requirements below
             */

            // req_filter["RQ_REQ_PATH"] = "AAAAAGAAE*";


            StreamWriter rfs = new StreamWriter(File.Open(req_file, FileMode.Create),
                                                Encoding.Default,
                                                1024);

            StreamWriter afs = new StreamWriter(File.Open(att_file, FileMode.Create),
                                                Encoding.Default,
                                                1024);

            foreach (Req r in req_filter.NewList())
            {
                string name = r.Name.Replace("\"", "").Replace("\t", "").Trim();

                Console.WriteLine("Req \"{0}\"", name);

                rfs.WriteLine(String.Join("\t", new String[] {
                    r.ID.ToString(),
                    r.ParentId.ToString(),
                    r["RQ_REQ_PATH"],
                    name,
                    r["RQ_VTS"].ToString()
                }));

                if (!r.HasAttachment)
                {
                    continue;
                }

                AttachmentFactory att_factory = r.Attachments;

                foreach (Attachment a in att_factory.NewList(""))
                {
                    Console.WriteLine("Attachment \"{0}\"", a.Name);

                    afs.WriteLine(String.Join("\t", new String[] {
                        r.ID.ToString(),
                        a.ID.ToString(),
                        a.Name,
                        a.FileSize.ToString(),
                        a.LastModified.ToShortDateString()
                    }));

                    IExtendedStorage storage = a.AttachmentStorage;
                    storage.ClientPath = Path.GetFullPath(att_path) + "\\";
                    storage.Load(a.Name, true);
                }
            }

            rfs.Close();
            afs.Close();

            tdc.Disconnect();
            tdc.Logout();

            Console.WriteLine("Disconnected.");
        }
        public bool Attach(
            int TestSetId,
            AttachmentType Type,
            string Path,
            string Description = default(string),
            string Name        = default(string))
        {
            bool success = false;

            try
            {
                if (!Connect(ServerUrl, Username, Password, Domain, Project))
                {
                    return(false);
                }

                TestSetFactory tsFact   = tdc.TestSetFactory;
                TestSet        tSet     = tsFact[TestSetId];
                string         tSetName = tSet.Name; //Strange ALM bug allows you to select a non existant tet set. Calling name ensures it exists

                AttachmentFactory attachFact = tSet.Attachments;
                Attachment        attach     = attachFact.AddItem(DBNull.Value);
                attach.FileName = Path;

                TDAPI_ATTACH_TYPE attachType = TDAPI_ATTACH_TYPE.TDATT_FILE;

                switch (Type)
                {
                case AttachmentType.File:
                case AttachmentType.file:
                    attachType = TDAPI_ATTACH_TYPE.TDATT_FILE;
                    break;

                case AttachmentType.URL:
                case AttachmentType.url:
                case AttachmentType.Url:
                    attachType = TDAPI_ATTACH_TYPE.TDATT_INTERNET;
                    break;
                }

                attach.Type = (int)attachType;

                if (Description != default(string))
                {
                    attach.Description = Description;
                }

                //Post will fail if attachment path is bad
                attach.Post();

                if ((Name != default(string)) && (attachType == TDAPI_ATTACH_TYPE.TDATT_FILE))
                {
                    attach.Rename(Name);
                    attach.Post();
                }
                success = true;
            }
            catch (COMException ce)
            {
                //If we get an error, delete the attachment
                //If the file path is invalid and the attachment never uploads, ALM throws an error but posts the attachment anyways
                //returning no attachment object. So the only way to detect this is to look for 0 sized attachments and delete them
                TestSetFactory    tsFact     = tdc.TestSetFactory;
                TestSet           tSet       = tsFact[TestSetId];
                AttachmentFactory attachFact = tSet.Attachments;
                List attachList = attachFact.NewList("");
                foreach (Attachment a in attachList)
                {
                    if (a.FileSizeEx == 0)
                    {
                        attachFact.RemoveItem(a.ID);
                    }
                }
                rr.AddErrorLine(HandleException(ce));
            }
            finally { Disconnect(); }

            return(success);
        }
示例#4
0
        public void UploadResults(TestCase currentTestCase)
        {
            string testFolder  = Convert.ToString(ExecutionSession.dictCommonData["QCFolder"]);
            string testSetName = currentTestCase.Category;

            TestSetFactory     tsFactory = (TestSetFactory)qcConnect.TestSetFactory;
            TestSetTreeManager tsTreeMgr = (TestSetTreeManager)qcConnect.TestSetTreeManager;
            TestSetFolder      tsFolder  = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolder);
            List    tsList  = tsFolder.FindTestSets(testSetName, false, null);
            TestSet testSet = tsList[1];

            tsFolder = (TestSetFolder)testSet.TestSetFolder;
            TSTestFactory tsTestFactory = (TSTestFactory)testSet.TSTestFactory;
            List          tsTestList    = tsTestFactory.NewList("");

            //  And finally, update each test case status:
            foreach (TSTest tsTest in tsTestList)
            {
                if (currentTestCase.TestCaseName == tsTest.Name.Remove(0, 3))
                {
                    RunFactory runFactory = (RunFactory)tsTest.RunFactory;
                    List       allfields  = runFactory.Fields;

                    String browserValue = tsTest["TC_USER_TEMPLATE_10"];

                    Run lastRun = (Run)tsTest.LastRun;

                    string     runName       = runFactory.UniqueRunName;
                    RunFactory objRunFactory = tsTest.RunFactory;
                    Run        theRun        = objRunFactory.AddItem(runName);
                    theRun.Name = runName;
                    theRun.CopyDesignSteps();
                    StepFactory Step     = theRun.StepFactory;
                    List        stepList = (List)Step.NewList("");
                    if (currentTestCase.OverAllResult == OverAllResult.PASS)
                    {
                        theRun.Status = "Passed";
                    }
                    else
                    {
                        theRun.Status = "Failed";
                    }
                    theRun.Post();

                    //Delete current attachment from QC test set test case
                    AttachmentFactory objAttachmentFactory = tsTest.Attachments;

                    var objCurrentAttachments = objAttachmentFactory.NewList("");

                    for (int objC = 1; objC <= objCurrentAttachments.Count; objC++)
                    {
                        try
                        {
                            objAttachmentFactory.RemoveItem(tsTest.Attachments.NewList("").Item(1).ID);
                        }
                        catch { }
                    }

                    IAttachment objAttachment = objAttachmentFactory.AddItem(DBNull.Value);
                    objAttachment.FileName = currentTestCase.QCHTMLReportPath;
                    objAttachment.Type     = 1;
                    objAttachment.Post();

                    string[] filePaths = System.IO.Directory.GetFiles(currentTestCase.QCScreenShotPath);
                    foreach (string file in filePaths)
                    {
                        objAttachment          = objAttachmentFactory.AddItem(DBNull.Value);
                        objAttachment.FileName = file;
                        objAttachment.Type     = 1;
                        objAttachment.Post();
                    }
                    break;
                }
            }
        }
        public void UploadResults(TB2.TestCase currentTestCase)
        {
            string testFolder  = @"Root\WCS 7up Core - 5022\zz Automation\PracticeExecution\Temp_Prashant\QA72_7_31";
            string testSetName = currentTestCase.Category;

            TestSetFactory     tsFactory = (TestSetFactory)qcConnect.TestSetFactory;
            TestSetTreeManager tsTreeMgr = (TestSetTreeManager)qcConnect.TestSetTreeManager;
            TestSetFolder      tsFolder  = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolder);
            List    tsList  = tsFolder.FindTestSets(testSetName, false, null);
            TestSet testSet = tsList[1];

            //foreach (TestSet testSet in tsList)
            //{
            tsFolder = (TestSetFolder)testSet.TestSetFolder;
            TSTestFactory tsTestFactory = (TSTestFactory)testSet.TSTestFactory;
            List          tsTestList    = tsTestFactory.NewList("");

            //  And finally, update each test case status:
            foreach (TSTest tsTest in tsTestList)
            {
                //System.Console.Out.WriteLine("Test Case ID: " + tsTest.ID + ", Test Case Name: " + tsTest.Name + "\n");
                if (currentTestCase.TestCaseName == tsTest.Name.Remove(0, 3))
                {
                    RunFactory runFactory = (RunFactory)tsTest.RunFactory;
                    List       allfields  = runFactory.Fields;

                    String browserValue = tsTest["TC_USER_TEMPLATE_10"];

                    // Console.WriteLine("Browser value : " + browserValue);

                    Run lastRun = (Run)tsTest.LastRun;

                    string     runName       = runFactory.UniqueRunName;
                    RunFactory objRunFactory = tsTest.RunFactory;
                    Run        theRun        = objRunFactory.AddItem(runName);
                    theRun.Name = runName;

                    //Get the count of test steps and compare it with the number of steps that were actually executed
                    //and define the Execution status accordinagly
                    theRun.CopyDesignSteps();
                    StepFactory Step     = theRun.StepFactory;
                    List        stepList = (List)Step.NewList("");
                    if (currentTestCase.OverAllResult == OverAllResult.PASS)
                    {
                        theRun.Status = "Passed";
                    }
                    else
                    {
                        theRun.Status = "Failed";
                    }
                    theRun.Post();

                    //Delete current attachment from QC test set test case
                    AttachmentFactory objAttachmentFactory = tsTest.Attachments;

objSkipExec:

                    var objCurrentAttachments = objAttachmentFactory.NewList("");


                    for (int objC = 1; objC <= objCurrentAttachments.Count; objC++)
                    {
                        try
                        {
                            objAttachmentFactory.RemoveItem(tsTest.Attachments.NewList("").Item(1).ID);
                        }
                        catch { }
                    }

                    if (objAttachmentFactory.NewList("").Count > 0)
                    {
                        goto objSkipExec;
                    }

                    IAttachment objAttachment = objAttachmentFactory.AddItem(DBNull.Value);
                    objAttachment.FileName = currentTestCase.HTMLReportPath;
                    objAttachment.Type     = 1;
                    objAttachment.Post();

                    string[] filePaths = System.IO.Directory.GetFiles(currentTestCase.ScreenShotPath);
                    foreach (string file in filePaths)
                    {
                        objAttachment          = objAttachmentFactory.AddItem(DBNull.Value);
                        objAttachment.FileName = file;
                        objAttachment.Type     = 1;
                        objAttachment.Post();
                    }
                    break;
                    // }
                }
            }
        }