private static QCTestCaseStep GetListTSTestVars(QCTestCase testCase) { QCTestCaseStepsColl steps = QCRestAPIConnect.GetTestCaseSteps(testCase.Id); foreach (QCTestCaseStep step in steps) { if (step.ElementsField.ContainsKey("link-test")) { return(step); } } return(null); }
private QCTestCaseStepsColl GetListTSTestSteps(QCTestCase testCase) { QCTestCaseStepsColl testCaseSteps = QCRestAPIConnect.GetTestCaseSteps(testCase.Id); foreach (QCTestCaseStep step in testCaseSteps) { if (step.ElementsField.ContainsKey("link-test")) { QCTestCaseStepsColl linkTestCaseSteps = QCRestAPIConnect.GetTestCasesSteps(new List <string>() { step.ElementsField["link-test"].ToString() }); return(linkTestCaseSteps); } } return(testCaseSteps); }
private string CheckLinkedTSTestName(QCTestCase testCase) { QCTestCaseStepsColl testCasesSteps = QCRestAPIConnect.GetTestCaseSteps(testCase.Id); foreach (QCTestCaseStep step in testCasesSteps) { if (step.ElementsField.ContainsKey("link-test")) { QCTestCase linkedTestCase = QCRestAPIConnect.GetTestCases(new List <string>() { step.ElementsField["link-test"].ToString() })[0]; return(linkedTestCase.Name + ";" + linkedTestCase.Id); } } return(null); }
private static void UpdateTestStep(QCTestCase test, ActivitiesGroup activitiesGroup, Activity identifiedActivity, ObservableList <ExternalItemFieldBase> designStepsFields, ObservableList <ExternalItemFieldBase> designStepsParamsFields) { QCTestCaseStepsColl testCaseDesignStep = QCRestAPIConnect.GetTestCasesSteps(new List <string> { test.Id }); //delete the un-needed steps foreach (QCTestCaseStep step in testCaseDesignStep) { if (activitiesGroup.ActivitiesIdentifiers.Where(x => x.IdentifiedActivity.ExternalID == step.Id.ToString()).FirstOrDefault() == null) { QCRestAPIConnect.DeleteEntity(ALM_Common.DataContracts.ResourceType.DESIGN_STEP, step.Id); } } //delete the existing parameters QCTestCaseParamsColl testCaseParams = QCRestAPIConnect.GetTestCaseParams(test.Id); if (testCaseParams.Count > 0) { for (int indx = 0; indx < testCaseParams.Count; indx++) { QCRestAPIConnect.DeleteEntity(ALM_Common.DataContracts.ResourceType.DESIGN_STEP_PARAMETERS, testCaseParams[indx].Id); } } foreach (QCTestCaseStep step in testCaseDesignStep) { //set item fields foreach (ExternalItemFieldBase field in designStepsFields) { if (field.ToUpdate || field.Mandatory) { if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA") { if (step.ElementsField.ContainsKey(field.ExternalID)) { step.ElementsField[field.ExternalID] = field.SelectedValue; } } } } step.ElementsField["name"] = identifiedActivity.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&&>>", identifiedActivity.Description); QCTestCaseParamsColl testParams = QCRestAPIConnect.GetTestCaseParams(test.Id); string paramsSigns = string.Empty; if (identifiedActivity.Variables.Count > 0) { paramsSigns = "<br />Parameters:<br />"; foreach (VariableBase var in identifiedActivity.Variables) { paramsSigns += "<<<" + var.Name.ToLower() + ">>><br />"; //try to add the paramter to the test case parameters list try { QCTestCaseParam newParam = new QCTestCaseParam(); //set item fields foreach (ExternalItemFieldBase field in designStepsParamsFields) { if (field.ToUpdate || field.Mandatory) { if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA") { newParam.ElementsField.Add(field.ExternalID, field.SelectedValue); } else { try { newParam.ElementsField.Add(field.ExternalID, "NA"); } catch { } } } } newParam.Name = var.Name.ToLower(); newParam.TestId = test.Id; QCItem itemTestCaseParam = ConvertObjectValuesToQCItem(newParam, ResourceType.TEST_CASE_PARAMETERS); QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_CASE_PARAMETERS, itemTestCaseParam); } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}"); } } } description = description.Replace("<<&Parameters&>>", paramsSigns); string actsDesc = string.Empty; if (identifiedActivity.Acts.Count > 0) { actsDesc = "Actions:<br />"; foreach (Act act in identifiedActivity.Acts) { actsDesc += act.Description + "<br />"; } } description = description.Replace("<<&Actions&>>", actsDesc); step.Description = description; step.ElementsField["expected"] = identifiedActivity.Expected; QCItem itemDesignStep = ConvertObjectValuesToQCItem(step, ResourceType.DESIGN_STEP, true); ALMResponseData response = QCRestAPIConnect.UpdateEntity(ResourceType.DESIGN_STEP, step.Id, itemDesignStep); identifiedActivity.ExternalID = step.Id; } }
public QC.QCTSTest ImportTSTest(QCTestInstance testInstance) { QC.QCTSTest newTSTest = new QC.QCTSTest(); QCTestCase testCase = QCRestAPIConnect.GetTestCases(new List <string>() { testInstance.TestId })[0]; string linkedTest = CheckLinkedTSTestName(testCase); if (testInstance != null) { //Get the TC general details if (linkedTest != null) { //Linked TC string[] linkTest = linkedTest.Split(';'); newTSTest.TestID = testInstance.Id; newTSTest.TestName = linkTest[0]; newTSTest.LinkedTestID = linkTest[1]; } else { //Regular TC newTSTest.TestID = testInstance.Id; newTSTest.TestName = testInstance.Name ?? testCase.Name; newTSTest.LinkedTestID = testInstance.TestId; } } //Get the TC design steps QCTestCaseStepsColl TSTestSteps = GetListTSTestSteps(testCase); foreach (QCTestCaseStep testcaseStep in TSTestSteps) { QC.QCTSTestStep newtsStep = new QC.QCTSTestStep(); newtsStep.StepID = testcaseStep.Id.ToString(); newtsStep.StepName = testcaseStep.Name; newtsStep.Description = testcaseStep.Description; newtsStep.Expected = testcaseStep.ElementsField["expected"].ToString(); newTSTest.Steps.Add(newtsStep); } //Get the TC parameters and their selected value if (linkedTest != null) { if (linkedTest.Split(';')[0] != testCase.Name) { if (newTSTest.Description == null) { newTSTest.Description = string.Empty; } newTSTest.Description = testCase.Name.ToString() + System.Environment.NewLine + newTSTest.Description; } //Linked TC QCTestCaseStep TSLinkedTestCaseStep = GetListTSTestVars(testCase); if (TSLinkedTestCaseStep != null) { FillRelevantDataForStepParams(newTSTest, TSLinkedTestCaseStep); } } else { ////Regular TC QCTestCaseStepsColl TSLinkedTestCaseSteps = QCRestAPIConnect.GetTestCaseSteps(testCase.Id); foreach (QCTestCaseStep step in TSLinkedTestCaseSteps) { FillRelevantDataForStepParams(newTSTest, step); } } //Get the TC execution history try { QCRunColl TSTestRuns = GetListTSTestRuns(testCase); foreach (QCRun run in TSTestRuns) { QC.QCTSTestRun newtsRun = new QC.QCTSTestRun(); newtsRun.RunID = run.Id; newtsRun.RunName = run.Name; newtsRun.Status = run.Status; newtsRun.ExecutionDate = (run.ElementsField["execution-date"]).ToString(); newtsRun.ExecutionTime = (run.ElementsField["execution-time"]).ToString(); newtsRun.Tester = (run.Owner).ToString(); newTSTest.Runs.Add(newtsRun); } } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Failed to pull QC test case RUN info", ex); newTSTest.Runs = new List <QC.QCTSTestRun>(); } return(newTSTest); }
private static ActivitiesGroup CheckIfTCAlreadyExistInRepo(BusinessFlow busFlow, QCTestInstance testInstance, QCTestCaseStepsColl tSTestCaseSteps) { ActivitiesGroup tcActivsGroup; ActivitiesGroup repoActivsGroup = null; QCTestCaseStepsColl relevantTestCaseSteps = QCRestAPIConnect.GetTestCaseSteps(testInstance.TestId); QCTestCaseStep relevantStep = null; foreach (QCTestCaseStep testcaseStep in relevantTestCaseSteps) { if (testcaseStep.ElementsField.ContainsKey("link-test")) { relevantStep = testcaseStep; } } if (relevantStep != null) { repoActivsGroup = GingerActivitiesGroupsRepo.Where(x => x.ExternalID == relevantStep.ElementsField["link-test"].ToString()).FirstOrDefault(); } if (repoActivsGroup == null) { repoActivsGroup = GingerActivitiesGroupsRepo.Where(x => x.ExternalID == testInstance.Id).FirstOrDefault(); } if (repoActivsGroup != null) { List <Activity> repoNotExistsStepActivity = GingerActivitiesRepo.Where(z => repoActivsGroup.ActivitiesIdentifiers.Select(y => y.ActivityExternalID).ToList().Contains(z.ExternalID)) .Where(x => !tSTestCaseSteps.Where(item => item.TestId == testInstance.TestId).Select(y => y.Id).ToList().Contains(x.ExternalID)).ToList(); tcActivsGroup = (ActivitiesGroup)repoActivsGroup.CreateInstance(); var ActivitySIdentifiersToRemove = tcActivsGroup.ActivitiesIdentifiers.Where(x => repoNotExistsStepActivity.Select(z => z.ExternalID).ToList().Contains(x.ActivityExternalID)); for (int indx = 0; indx < tcActivsGroup.ActivitiesIdentifiers.Count; indx++) { if ((indx < tcActivsGroup.ActivitiesIdentifiers.Count) && (ActivitySIdentifiersToRemove.Contains(tcActivsGroup.ActivitiesIdentifiers[indx]))) { tcActivsGroup.ActivitiesIdentifiers.Remove(tcActivsGroup.ActivitiesIdentifiers[indx]); indx--; } } tcActivsGroup.ExternalID2 = testInstance.Id; busFlow.AddActivitiesGroup(tcActivsGroup); busFlow.ImportActivitiesGroupActivitiesFromRepository(tcActivsGroup, GingerActivitiesRepo, true, true); busFlow.AttachActivitiesGroupsAndActivities(); } else //TC not exist in Ginger repository so create new one { tcActivsGroup = new ActivitiesGroup(); tcActivsGroup.Name = testInstance.Name; if (relevantStep == null) { tcActivsGroup.ExternalID = testInstance.Id; tcActivsGroup.ExternalID2 = testInstance.Id; } else { tcActivsGroup.ExternalID = relevantStep.ElementsField["link-test"].ToString(); tcActivsGroup.ExternalID2 = testInstance.Id; } busFlow.AddActivitiesGroup(tcActivsGroup); } return(tcActivsGroup); }