Пример #1
0
        private static bool ExportActivityAsTestStep(Test test, Activity activity)
        {
            DesignStepFactory stepF;
            DesignStep        step = null;
            List stepsList;

            stepF = test.DesignStepFactory;

            if (string.IsNullOrEmpty(activity.ExternalID) == false)
            {
                //look for existing step
                stepsList = stepF.NewList("");
                if (stepsList != null && stepsList.Count > 0)
                {
                    foreach (DesignStep s in stepsList)
                    {
                        if (s.ID.ToString() == activity.ExternalID)
                        {
                            step = s;//step already exist
                            break;
                        }
                    }
                }
            }

            if (step == null)
            {
                //create new step
                step = stepF.AddItem(System.DBNull.Value);
            }

            step.StepName = activity.ActivityName;
            string descriptionTemplate =
                "<html><body><div align=\"left\"><font face=\"Arial\"><span style=\"font-size:8pt\"><<&Description&&>><br /><<&Parameters&>><br /><<&Actions&>></span></font></div></body></html>";
            string     description = descriptionTemplate.Replace("<<&Description&&>>", activity.Description);
            StepParams testParams  = test.Params;
            string     paramsSigns = string.Empty;

            if (activity.Variables.Count > 0)
            {
                paramsSigns = "<br />Parameters:<br />";
                foreach (VariableBase var in activity.Variables)
                {
                    paramsSigns += "&lt;&lt;&lt;" + var.Name.ToLower() + "&gt;&gt;&gt;<br />";
                    //try to add the parameter to the test case parameters list
                    try
                    {
                        testParams.AddParam(var.Name.ToLower(), "String");
                        testParams.Save();
                        test.Post();
                    }
                    catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); }
                }
            }
            description = description.Replace("<<&Parameters&>>", paramsSigns);

            string actsDesc = string.Empty;

            if (activity.Acts.Count > 0)
            {
                actsDesc = "Actions:<br />";
                foreach (Act act in activity.Acts)
                {
                    actsDesc += act.Description + "<br />";
                }
            }
            description          = description.Replace("<<&Actions&>>", actsDesc);
            step.StepDescription = description;

            string expectedTemplate =
                "<html><body><div align=\"left\"><font face=\"Arial\"><span style=\"font-size:8pt\"><<&Expected&&>></span></font></div></body></html>";

            step.StepExpectedResult = expectedTemplate.Replace("<<&Expected&&>>", activity.Expected);

            step.Post();

            activity.ExternalID = step.ID.ToString();
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Export Activities Group details to QC, can be used for creating new matching QC Test Case or updating an existing one
        /// </summary>
        /// <param name="activitiesGroup">Activities Group to Export</param>
        /// <param name="mappedTest">The QC Test Case which mapped to the Activities Group (in case exist) and needs to be updated</param>
        /// <param name="uploadPath">Upload path in QC Test Plan</param>
        /// <param name="result">Export error result</param>
        /// <returns></returns>
        public static bool ExportActivitiesGroupToQC(ActivitiesGroup activitiesGroup, Test mappedTest, string uploadPath, ObservableList <ExternalItemFieldBase> testCaseFields, ref string result)
        {
            Test test;

            try
            {
                if (mappedTest == null)
                {
                    //##create new Test Case in QC
                    TestFactory TestF = (TestFactory)mTDConn.TestFactory;
                    test      = (Test)TestF.AddItem(System.DBNull.Value);
                    test.Type = "MANUAL";

                    //set the upload path
                    TreeManager  treeM            = (TreeManager)mTDConn.TreeManager;
                    ISysTreeNode testParentFolder = (ISysTreeNode)treeM.get_NodeByPath(uploadPath);
                    test["TS_SUBJECT"] = testParentFolder.NodeID;
                }
                else
                {
                    //##update existing test case
                    test = ImportFromQC.GetQCTest(activitiesGroup.ExternalID);

                    //delete the un-needed steps
                    DesignStepFactory stepF = test.DesignStepFactory;
                    List stepsList          = stepF.NewList("");
                    foreach (DesignStep step in stepsList)
                    {
                        if (activitiesGroup.ActivitiesIdentifiers.Where(x => x.IdentifiedActivity.ExternalID == step.ID.ToString()).FirstOrDefault() == null)
                        {
                            stepF.RemoveItem(step.ID);
                        }
                    }

                    //delete the existing parameters
                    StepParams testParams = test.Params;
                    if (testParams.Count > 0)
                    {
                        for (int indx = 0; indx < testParams.Count; indx++)
                        {
                            testParams.DeleteParam(testParams.ParamName[indx]);
                            testParams.Save();
                        }
                    }
                }

                //set item fields
                foreach (ExternalItemFieldBase field in testCaseFields)
                {
                    if (field.ToUpdate || field.Mandatory)
                    {
                        if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                        {
                            test[field.ID] = field.SelectedValue;
                        }
                        else
                        {
                            try { test[field.ID] = "NA"; }
                            catch { }
                        }
                    }
                }

                //post the test
                test.Name = activitiesGroup.Name;
                test.Post();
                activitiesGroup.ExternalID  = test.ID.ToString();
                activitiesGroup.ExternalID2 = test.ID.ToString();

                //Add/update all test steps + Parameters
                foreach (ActivityIdentifiers actIdent in activitiesGroup.ActivitiesIdentifiers)
                {
                    ExportActivityAsTestStep(test, (Activity)actIdent.IdentifiedActivity);
                }

                return(true);
            }
            catch (Exception ex)
            {
                result = "Unexpected error occurred- " + ex.Message;
                Reporter.ToLog(eLogLevel.ERROR, "Failed to export the Activities Group to QC/ALM", ex);
                return(false);
            }
        }