public override ObservableList <ExternalItemFieldBase> GetALMItemFields(BackgroundWorker bw, bool online, bool useREST) { if (!useREST) { return(ImportFromQC.GetALMItemFields()); } else { return(ImportFromQC.GetQCEntityFieldsREST(ALM_Common.DataContracts.ResourceType.DEFECT)); // currently DEFECTS supported. May be extended if needed } }
public override Dictionary <Guid, string> CreateNewALMDefects(Dictionary <Guid, Dictionary <string, string> > defectsForOpening, bool useREST) { if (!useREST) { // do nothing return(new Dictionary <Guid, string>()); } else { return(ImportFromQC.CreateNewDefectQCREST(defectsForOpening)); } }
public static bool ExportBusinessFlowToQC(BusinessFlow businessFlow, TestSet mappedTestSet, string uploadPath, ObservableList <ExternalItemFieldBase> testSetFields, ref string result) { TestSet testSet; ObservableList <ActivitiesGroup> existingActivitiesGroups = new ObservableList <ActivitiesGroup>(); try { if (mappedTestSet == null) { //##create new Test Set in QC TestSetFactory TestSetF = (TestSetFactory)mTDConn.TestSetFactory; testSet = (TestSet)TestSetF.AddItem(System.DBNull.Value); //set the upload path TestSetTreeManager treeM = (TestSetTreeManager)mTDConn.TestSetTreeManager; ISysTreeNode testSetParentFolder = (ISysTreeNode)treeM.get_NodeByPath(uploadPath); testSet.TestSetFolder = testSetParentFolder.NodeID; } else { //##update existing test set //testSet = mappedTestSet; testSet = ImportFromQC.GetQCTestSet(mappedTestSet.ID.ToString()); TSTestFactory testsF = (TSTestFactory)testSet.TSTestFactory; List tsTestsList = testsF.NewList(""); foreach (TSTest tsTest in tsTestsList) { ActivitiesGroup ag = businessFlow.ActivitiesGroups.Where(x => (x.ExternalID == tsTest.TestId.ToString() && x.ExternalID2 == tsTest.ID.ToString())).FirstOrDefault(); if (ag == null) { testsF.RemoveItem(tsTest.ID); } else { existingActivitiesGroups.Add(ag); } } } //set item fields foreach (ExternalItemFieldBase field in testSetFields) { if (field.ToUpdate || field.Mandatory) { if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA") { testSet[field.ID] = field.SelectedValue; } else { try { testSet[field.ID] = "NA"; } catch { } } } } //post the test set testSet.Name = businessFlow.Name; try { testSet.Post(); } catch (Exception ex) { if (ex.Message.Contains("The Test Set already exists")) { result = "Cannot export " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + "- The Test Set already exists in the selected folder. "; Reporter.ToLog(eLogLevel.ERROR, result, ex); return(false); } //Searching for the testset in case it was created in ALM although getting exception TestSetFactory TSetFact = mTDConn.TestSetFactory; TDFilter tsFilter = TSetFact.Filter; TestSetTreeManager treeM = (TestSetTreeManager)mTDConn.TestSetTreeManager; ISysTreeNode testSetParentFolder = (ISysTreeNode)treeM.get_NodeByPath(uploadPath); try { tsFilter["CY_FOLDER_ID"] = "" + testSetParentFolder.NodeID + ""; } catch (Exception e) { tsFilter["CY_FOLDER_ID"] = "\"" + testSetParentFolder.Path.ToString() + "\""; Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}", e); } List TestsetList = TSetFact.NewList(tsFilter.Text); foreach (TestSet set in TestsetList) { if (set.Name == businessFlow.Name) { testSet = set; break; } } } businessFlow.ExternalID = testSet.ID.ToString(); //Add missing test cases TSTestFactory testCasesF = testSet.TSTestFactory; foreach (ActivitiesGroup ag in businessFlow.ActivitiesGroups) { if (existingActivitiesGroups.Contains(ag) == false && string.IsNullOrEmpty(ag.ExternalID) == false && ImportFromQC.GetQCTest(ag.ExternalID) != null) { TSTest tsTest = testCasesF.AddItem(ag.ExternalID); if (tsTest != null) { ag.ExternalID2 = tsTest.ID;//the test case instance ID in the test set- used for exporting the execution details } } else { foreach (ActivityIdentifiers actIdent in ag.ActivitiesIdentifiers) { ExportActivityAsTestStep(ImportFromQC.GetQCTest(ag.ExternalID), (Activity)actIdent.IdentifiedActivity); } } } return(true); } catch (Exception ex) { result = "Unexpected error occurred- " + ex.Message; Reporter.ToLog(eLogLevel.ERROR, "Failed to export the " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + " to QC/ALM", ex); return(false); } }
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); } }
/// <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); } }
private void SetTestSetsData() { mQcTestCasesList.Clear(); mTestCaseDetailsList.Clear(); mAutomatedPrecentage = 0; mExecutedNumber = 0; mRunsNumber = 0; mPassedRunsPrecentage = 0; if (mSelectQcTestSets != null && mSelectQcTestSets.Count > 0) { foreach (QCTestSetTreeItem testSetItem in mSelectQcTestSets) { QCTestSet TS = new QCTestSet(); TS.TestSetID = testSetItem.TestSetID; TS.TestSetName = testSetItem.TestSetName; TS.TestSetPath = testSetItem.Path; TS = ImportFromQC.ImportTestSetData(TS);//get test cases foreach (QCTSTest tc in TS.Tests) { mQcTestCasesList.Add(tc); int automatedStepsCouter = 0; QCManagerReportTestCaseDetails testCaseDetails = new QCManagerReportTestCaseDetails(); testCaseDetails.TestSetID = TS.TestSetID; testCaseDetails.TestSetName = TS.TestSetName; testCaseDetails.TestCaseID = tc.LinkedTestID; testCaseDetails.TestCaseName = tc.TestName; //check if the TC is already exist in repository ActivitiesGroup repoActivsGroup = null; ObservableList <ActivitiesGroup> activitiesGroup = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ActivitiesGroup>(); if (tc.LinkedTestID != null && tc.LinkedTestID != string.Empty) { repoActivsGroup = activitiesGroup.Where(x => x.ExternalID == tc.LinkedTestID).FirstOrDefault(); } if (repoActivsGroup == null) { repoActivsGroup = activitiesGroup.Where(x => x.ExternalID == tc.TestID).FirstOrDefault(); } if (repoActivsGroup != null) { testCaseDetails.ActivitiesGroupID = repoActivsGroup.Guid; testCaseDetails.ActivitiesGroupName = repoActivsGroup.Name; //check for automation percentage foreach (QCTSTestStep step in tc.Steps) { ObservableList <Activity> activities = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <Activity>(); Activity repoStepActivity = activities.Where(x => x.ExternalID == step.StepID).FirstOrDefault(); if (repoStepActivity != null) { if (repoStepActivity.AutomationStatus == Activity.eActivityAutomationStatus.Automated) { automatedStepsCouter++; } } } } else { testCaseDetails.ActivitiesGroupName = "NA"; } //set automation percentage double automatedActsPrecanteg = 0; if (tc.Steps.Count > 0) { automatedActsPrecanteg = ((double)automatedStepsCouter / (double)tc.Steps.Count); mAutomatedPrecentage += automatedActsPrecanteg; automatedActsPrecanteg = Math.Floor(automatedActsPrecanteg * 100); testCaseDetails.ActivitiesGroupAutomationPrecentage = automatedActsPrecanteg.ToString() + "%"; } else { testCaseDetails.ActivitiesGroupAutomationPrecentage = "0%"; } //set execution details CalculateTCExecutionDetails(tc, testCaseDetails); mTestCaseDetailsList.Add(testCaseDetails); } } } //get the executers names var groups = mQcTestCasesList.SelectMany(x => x.Runs).GroupBy(y => y.Tester) .Select(n => new { TesterName = n.Key.ToString(), Count = n.Count() } ) .OrderBy(n => n.TesterName); ExecutionTesterFilterComboBox.SelectionChanged -= ExecutionTesterFilterComboBox_SelectionChanged; ExecutionTesterFilterComboBox.SelectedItem = null; ExecutionTesterFilterComboBox.Items.Clear(); ExecutionTesterFilterComboBox.Items.Add("Any"); foreach (var v in groups) { ExecutionTesterFilterComboBox.Items.Add(v.TesterName); } ExecutionTesterFilterComboBox.SelectedValue = "Any"; ExecutionTesterFilterComboBox.SelectionChanged += ExecutionTesterFilterComboBox_SelectionChanged; }
public override ObservableList <ExternalItemFieldBase> GetALMItemFields(BackgroundWorker bw, bool online, ALM_Common.DataContracts.ResourceType resourceType) { return(ImportFromQC.GetALMItemFields()); }
public List <QCTSTest> GetTSQCTestsList(string testSetID, List <string> TCsIDs = null) { return(ImportFromQC.GetTSQCTestsList(testSetID, TCsIDs)); }
public TestSet GetQCTestSet(string testSetID) { return(ImportFromQC.GetQCTestSet(testSetID)); }
public BusinessFlow ConvertQCTestSetToBF(QCTestSet testSet) { return(ImportFromQC.ConvertQCTestSetToBF(testSet)); }
public void UpdateBusinessFlow(ref BusinessFlow businessFlow, List <QCTSTest> tcsList) { ImportFromQC.UpdateBusinessFlow(ref businessFlow, tcsList); }
public QCTestSet ImportTestSetData(QCTestSet TS) { return(ImportFromQC.ImportTestSetData(TS)); }
public override ObservableList <ExternalItemFieldBase> GetALMItemFields(BackgroundWorker bw, bool online, ResourceType resourceType) { return(UpdatedAlmFields(ImportFromQC.GetALMItemFields())); }
public void UpdatedQCTestInBF(ref BusinessFlow businessFlow, List <ALMTSTest> tcsList) { ImportFromQC.UpdatedQCTestInBF(ref businessFlow, tcsList); }
public ALMTestSet ImportTestSetData(ALMTestSet TS) { return(ImportFromQC.ImportTestSetData(TS)); }