Exemplo n.º 1
0
        public static bool ExportExecutionDetailsToQC(BusinessFlow bizFlow, ref string result, PublishToALMConfig publishToALMConfig = null)
        {
            result = string.Empty;
            if (bizFlow.ExternalID == "0" || String.IsNullOrEmpty(bizFlow.ExternalID))
            {
                result = GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + ": " + bizFlow.Name + " is missing ExternalID, cannot locate QC TestSet without External ID";
                return(false);
            }

            try
            {
                //get the BF matching test set
                TestSet testSet = ImportFromQC.GetQCTestSet(bizFlow.ExternalID);//bf.externalID holds the TestSet TSTests collection id
                if (testSet != null)
                {
                    //get the Test set TC's
                    List <TSTest> qcTSTests = ImportFromQC.GetTSTestsList(testSet); //list of TSTest's on main TestSet in TestLab

                    //get all BF Activities groups
                    ObservableList <ActivitiesGroup> activGroups = bizFlow.ActivitiesGroups;
                    if (activGroups.Count > 0)
                    {
                        foreach (ActivitiesGroup activGroup in activGroups)
                        {
                            if ((publishToALMConfig.FilterStatus == FilterByStatus.OnlyPassed && activGroup.RunStatus == eActivitiesGroupRunStatus.Passed) ||
                                (publishToALMConfig.FilterStatus == FilterByStatus.OnlyFailed && activGroup.RunStatus == eActivitiesGroupRunStatus.Failed) ||
                                publishToALMConfig.FilterStatus == FilterByStatus.All)
                            {
                                TSTest tsTest = null;
                                //go by TC ID = TC Instance ID
                                tsTest = qcTSTests.Where(x => x.TestId == activGroup.ExternalID && x.ID == activGroup.ExternalID2).FirstOrDefault();
                                if (tsTest == null)
                                {
                                    //go by Linked TC ID + TC Instance ID
                                    tsTest = qcTSTests.Where(x => ImportFromQC.GetTSTestLinkedID(x) == activGroup.ExternalID && x.ID == activGroup.ExternalID2).FirstOrDefault();
                                }
                                if (tsTest == null)
                                {
                                    //go by TC ID
                                    tsTest = qcTSTests.Where(x => x.TestId == activGroup.ExternalID).FirstOrDefault();
                                }
                                if (tsTest != null)
                                {
                                    //get activities in group
                                    List <Activity> activities   = (bizFlow.Activities.Where(x => x.ActivitiesGroupID == activGroup.Name)).Select(a => a).ToList();
                                    string          TestCaseName = PathHelper.CleanInValidPathChars(tsTest.TestName);
                                    if ((publishToALMConfig.VariableForTCRunName == null) || (publishToALMConfig.VariableForTCRunName == string.Empty))
                                    {
                                        String timeStamp = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss");
                                        publishToALMConfig.VariableForTCRunName = "GingerRun_" + timeStamp;
                                    }

                                    RunFactory runFactory = (RunFactory)tsTest.RunFactory;
                                    Run        run        = (Run)runFactory.AddItem(publishToALMConfig.VariableForTCRunNameCalculated);

                                    // Attach ActivityGroup Report if needed
                                    if (publishToALMConfig.ToAttachActivitiesGroupReport)
                                    {
                                        if ((activGroup.TempReportFolder != null) && (activGroup.TempReportFolder != string.Empty) &&
                                            (System.IO.Directory.Exists(activGroup.TempReportFolder)))
                                        {
                                            //Creating the Zip file - start
                                            string targetZipPath = System.IO.Directory.GetParent(activGroup.TempReportFolder).ToString();
                                            string zipFileName   = targetZipPath + "\\" + TestCaseName.ToString() + "_GingerHTMLReport.zip";

                                            if (!System.IO.File.Exists(zipFileName))
                                            {
                                                ZipFile.CreateFromDirectory(activGroup.TempReportFolder, zipFileName);
                                            }
                                            else
                                            {
                                                System.IO.File.Delete(zipFileName);
                                                ZipFile.CreateFromDirectory(activGroup.TempReportFolder, zipFileName);
                                            }
                                            System.IO.Directory.Delete(activGroup.TempReportFolder, true);
                                            //Creating the Zip file - finish
                                            //Attaching Zip file - start
                                            AttachmentFactory      attachmentFactory = (AttachmentFactory)run.Attachments;
                                            TDAPIOLELib.Attachment attachment        = (TDAPIOLELib.Attachment)attachmentFactory.AddItem(System.DBNull.Value);
                                            attachment.Description = "TC Ginger Execution HTML Report";
                                            attachment.Type        = 1;
                                            attachment.FileName    = zipFileName;
                                            attachment.Post();

                                            //Attaching Zip file - finish
                                            System.IO.File.Delete(zipFileName);
                                        }
                                    }


                                    //create run with activities as steps
                                    run.CopyDesignSteps();
                                    run.Post();
                                    StepFactory stepF     = run.StepFactory;
                                    List        stepsList = stepF.NewList("");

                                    //int i = 0;
                                    int index = 1;
                                    foreach (Step step in stepsList)
                                    {
                                        //search for matching activity based on ID and not order, un matching steps need to be left as No Run
                                        int      stepDesignID     = (stepsList[index]).Field("ST_DESSTEP_ID");
                                        Activity matchingActivity = activities.Where(x => x.ExternalID == stepDesignID.ToString()).FirstOrDefault();
                                        if (matchingActivity != null)
                                        {
                                            switch (matchingActivity.Status)
                                            {
                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed:
                                                step.Status = "Failed";
                                                List <IAct> failedActs = matchingActivity.Acts.Where(x => x.Status == Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed).ToList();
                                                string      errors     = string.Empty;
                                                foreach (Act act in failedActs)
                                                {
                                                    errors += act.Error + Environment.NewLine;
                                                }
                                                step["ST_ACTUAL"] = errors;
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.NA:
                                                step.Status       = "N/A";
                                                step["ST_ACTUAL"] = "NA";
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed:
                                                step.Status       = "Passed";
                                                step["ST_ACTUAL"] = "Passed as expected";
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped:
                                                //step.Status = "No Run";
                                                step.Status       = "N/A";
                                                step["ST_ACTUAL"] = "Skipped";
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Pending:
                                                step.Status       = "No Run";
                                                step["ST_ACTUAL"] = "Was not executed";
                                                break;

                                            case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Running:
                                                step.Status       = "Not Completed";
                                                step["ST_ACTUAL"] = "Not Completed";
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            //Step not exist in Ginger so left as "No Run" unless it is step data
                                            if (step.Name.ToUpper() == "STEP DATA")
                                            {
                                                step.Status = "Passed";
                                            }
                                            else
                                            {
                                                step.Status = "No Run";
                                            }
                                        }
                                        step.Post();
                                        index++;
                                    }

                                    //get all execution status for all steps
                                    ObservableList <string> stepsStatuses = new ObservableList <string>();
                                    foreach (Step step in stepsList)
                                    {
                                        stepsStatuses.Add(step.Status);
                                    }

                                    //update the TC general status based on the activities status collection.
                                    if (stepsStatuses.Where(x => x == "Failed").Count() > 0)
                                    {
                                        run.Status = "Failed";
                                    }
                                    else if (stepsStatuses.Where(x => x == "No Run").Count() == stepsList.Count || stepsStatuses.Where(x => x == "N/A").Count() == stepsList.Count)
                                    {
                                        run.Status = "No Run";
                                    }
                                    else if (stepsStatuses.Where(x => x == "Passed").Count() == stepsList.Count || (stepsStatuses.Where(x => x == "Passed").Count() + stepsStatuses.Where(x => x == "N/A").Count()) == stepsList.Count)
                                    {
                                        run.Status = "Passed";
                                    }
                                    else
                                    {
                                        run.Status = "Not Completed";
                                    }
                                    run.Post();
                                }
                                else
                                {
                                    //No matching TC was found for the ActivitiesGroup in QC
                                    result = "Matching TC's were not found for all " + GingerDicser.GetTermResValue(eTermResKey.ActivitiesGroups) + " in QC/ALM.";
                                }
                            }
                        }
                    }
                    else
                    {
                        //No matching Test Set was found for the BF in QC
                        result = "No matching Test Set was found in QC/ALM.";
                    }
                }
                if (result == string.Empty)
                {
                    result = "Export performed successfully.";
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                result = "Unexpected error occurred- " + ex.Message;
                Reporter.ToLog(eLogLevel.ERROR, "Failed to export execution details to QC/ALM", ex);
                //if (!silentMode)
                //    Reporter.ToUser(eUserMsgKey.ErrorWhileExportingExecDetails, ex.Message);
                return(false);
            }
        }
Exemplo n.º 2
0
        private static void ConnectALMQCAndUpdateTestRuns(string testFolderPath, string testSetName, string Test_Name)
        {
            TDConnection qcConn;
            string       url = "https://abc.com";

            try
            {
                qcConn = new TDConnection();
                qcConn.InitConnection(url, almDomain, GeneralMethods.Decrypt(almPassword));
                qcConn.ConnectProject(almProjectName, almUserName, GeneralMethods.Decrypt(almPassword));
                //qcConn.InitConnectionEx(url);
                //qcConn.ConnectProjectEx(domain, projectName, userName, Password.Decrypt(KeyFunctions.GetConfigData("LAN.EncPassword"), userDomain + "-" + userName));
                ////qcConn.ConnectProjectEx(domain, projectName, userName, password, userDomain + "-" + userName));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return;
            }


            if (qcConn.ProjectConnected)
            {
                var testInfo  = new List <string>();
                var tsTreeMgr = (TestSetTreeManager)qcConn.TestSetTreeManager;
                var tsFolder  = (TestSetFolder)tsTreeMgr.get_NodeByPath(almFolderPath);
                //var tsFolder = (TestSetFolder)tsTreeMgr.get_NodeById(22703);
                //var tsFolder = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolderPath);
                var attchFactory = (AttachmentFactory)tsFolder.Attachments;
                //string testname1 = tsFolder.Name;
                //var set1 = tsFolder.get_Child(1);
                int nodeid = tsFolder.NodeID;
                var tsList = tsFolder.FindTestSets(testSetName, false, null);
                //var tsList = tsFolder.FindTestSets(testSetName, true,null);
                foreach (TestSet ts in tsList)
                {
                    var tstFolder     = (TestSetFolder)ts.TestSetFolder;
                    var tsTestFactory = (TSTestFactory)ts.TSTestFactory;
                    var mylist        = tsTestFactory.NewList("");
                    foreach (TSTest tsTest in mylist)
                    {
                        if (tsTest.Name.Equals(Test_Name))
                        {
                            var runFactory = (RunFactory)tsTest.RunFactory;

                            var run = (Run)runFactory.AddItem("AutRun_" + Reports.starttime);
                            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.
                            run.Status = almTestStatus;
                            run.Post();
                            AttachmentFactory      attachmentFactory = (AttachmentFactory)tsTest.Attachments;
                            TDAPIOLELib.Attachment attachment        = (TDAPIOLELib.Attachment)attachmentFactory.AddItem(System.DBNull.Value);
                            attachment.Description = "Attached Automation execution result";
                            attachment.Type        = 1;
                            if (almReportAttachmentType.ToLower() == "word" && Reports.isWordReport)
                            {
                                attachment.FileName = WordReport.reportpath;
                            }
                            if (almReportAttachmentType.ToLower() == "pdf" && Reports.isPdfReport)
                            {
                                attachment.FileName = PDFReport.reportpath;
                            }
                            attachment.Post();

                            StepFactory rsFactory      = (StepFactory)run.StepFactory;
                            dynamic     rdata_stepList = rsFactory.NewList("");
                            var         rstepList      = (TDAPIOLELib.List)rdata_stepList;
                            foreach (dynamic rstep in rstepList)
                            {
                                rstep.Status = almTestStatus;
                                rstep.Post();
                            }
                        }
                    }
                }
            }
        }