public static void CopySharedSteps(ITestCase slave, params ISharedStepReference[] ss) { foreach (var sharedStep in ss) { ISharedStepReference sharedStepReference = slave.CreateSharedStepReference(); sharedStepReference.SharedStepId = sharedStep.SharedStepId; slave.Actions.Add(sharedStepReference); } }
/// <summary> /// Adds the new shared step internal. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="addedSharedStepGuids">The added shared step guids.</param> /// <param name="currentStep">The current step.</param> private void AddNewSharedStepInternal(TestCase testCase, List <Guid> addedSharedStepGuids, TestStep currentStep, int sharedStepId) { ISharedStep sharedStep = ExecutionContext.TestManagementTeamProject.SharedSteps.Find(sharedStepId); ISharedStepReference sharedStepReferenceCore = testCase.ITestCase.CreateSharedStepReference(); sharedStepReferenceCore.SharedStepId = sharedStep.Id; testCase.ITestCase.Actions.Add(sharedStepReferenceCore); addedSharedStepGuids.Add(currentStep.TestStepGuid); }
/// <summary> /// Generates all the step data from a set of TFS test actions /// </summary> /// <param name="actions">Collection of steps from the tc.</param> /// <param name="id">TFS tc id for displaying a helpful error message.</param> /// <param name="site">Required for pushing embedded steps to matching Site.</param> /// <returns></returns> public List <TestStepData> GetStepData(TestActionCollection actions, int id, Site site) { List <TestStepData> stepList = new List <TestStepData>(); foreach (ITestAction action in actions) { if (action is ISharedStepReference) { // if action is a shared step, ensure it is pushed to RF ISharedStepReference sharedRef = action as ISharedStepReference; var failures = this.Operations.CopyTestToRainforest(new List <int> { sharedRef.SharedStepId }, null, site).Result; // get the RFID for the TFS SharedStep int?rfId = this.GetRFID(sharedRef.SharedStepId); if (rfId == null) { throw new Core.ServiceException(Core.Error.TFSSharedTestDoesNotExist, sharedRef.SharedStepId.ToString()); } // add to list stepList.Add(new TestStepData(sharedRef.SharedStepId, rfId, null, null)); } else if (action is ITestStep) { // action is a normal step, not shared ITestStep step = action as ITestStep; stepList.Add(new TestStepData(null, null, Regex.Replace(step.Title, @"<[^>]*>", ""), Regex.Replace(step.ExpectedResult, @"<[^>]*>", ""))); // check for empty step if (stepList.Last().Title.Trim().Equals("")) { stepList.RemoveAt(stepList.Count - 1); continue; } var lastExpectedResult = stepList.Last().ExpectedResult.Trim(); // check for empty expected result if (lastExpectedResult.Equals("")) { throw new Core.ServiceException(Core.Error.EmptyExpectedResult, id.ToString()); } // check for a question mark on the expected result if (lastExpectedResult.Trim().Last() != '?') { stepList.Last().ExpectedResult += '?'; } } else { throw new Exception("TestCase action is unknown type."); } // TOEX -> this case shouldn't be hit ever } return(stepList); }
/// <summary> /// Creates the new shared step. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="sharedStepTitle">The shared step title.</param> /// <param name="stepTitle">The step title.</param> /// <param name="expectedResult">The expected result.</param> /// <returns>the shared step core object</returns> public static ISharedStep CreateNewSharedStep(TestCase testCase, string sharedStepTitle, string stepTitle, string expectedResult) { ISharedStepReference sharedStepReferenceCore = testCase.ITestCase.CreateSharedStepReference(); ISharedStep sharedStepCore = ExecutionContext.TestManagementTeamProject.SharedSteps.Create(); sharedStepReferenceCore.SharedStepId = sharedStepCore.Id; sharedStepCore.Title = sharedStepTitle; ITestStep testStepCore = sharedStepCore.CreateTestStep(); testStepCore.ExpectedResult = expectedResult; testStepCore.Title = stepTitle; sharedStepCore.Actions.Add(testStepCore); return sharedStepCore; }
private void HandleSharedStep() { if (IsSharedStep(_currentStep)) { _currentSharedStepsPointer = 0; _currentSharedStep = (ISharedStepReference)_currentStep; ISharedStep ss = _currentSharedStep.FindSharedStep(); TestActionCollection sharedActions = ss.Actions; _currentSharedTestStepResult = CreateSharedStepResult(_currentSharedStep) as ISharedStepResult; _currentSharedSteps.AddRange(sharedActions); _currentStep = _currentSharedSteps[_currentSharedStepsPointer++]; } }
/// <summary> /// Создать нумерованный многоуровневый список Word /// </summary> public void CreateMultiLevelList(Word.Paragraph paragraph, Word.ListTemplate listTemplate, List <ITestCase> testCase, int Index) { // Добавить название тест кейса на первый уровень нумерованного многоуровневого списка paragraph.Range.Text = testCase.ElementAt(Index).Title; paragraph.Range.SetListLevel(1); paragraph.Range.ListFormat.ApplyListTemplateWithLevel(listTemplate, ContinuePreviousList: true, ApplyTo: WdListApplyTo.wdListApplyToSelection, DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior, ApplyLevel: 1); paragraph.Range.InsertParagraphAfter(); // Если в тест кейсе нет Actions if (testCase.ElementAt(Index).Actions.Count == 0) { paragraph.Range.Text = "Тест кейс пуст!"; paragraph.Range.SetListLevel(2); paragraph.Range.ListFormat.ApplyListTemplateWithLevel(listTemplate, ContinuePreviousList: true, ApplyTo: WdListApplyTo.wdListApplyToSelection, DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior, ApplyLevel: 2); paragraph.Range.InsertParagraphAfter(); } ISharedStep sharedStep = null; ISharedStepReference sharedStepReference = null; for (int i = 0; i < testCase.ElementAt(Index).Actions.Count; i++) { sharedStepReference = testCase.ElementAt(Index).Actions.ElementAt(i) as ISharedStepReference; // Добавить общий шаг if (sharedStepReference != null) { // Добавить текст общего шага на второй уровень нумерованного многоуровневого списка sharedStep = sharedStepReference.FindSharedStep(); paragraph.Range.Text = sharedStep.Title + "\t(ОБЩИЙ ШАГ)"; paragraph.Range.SetListLevel(2); paragraph.Range.ListFormat.ApplyListTemplateWithLevel(listTemplate, ContinuePreviousList: true, ApplyTo: WdListApplyTo.wdListApplyToSelection, DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior, ApplyLevel: 2); paragraph.Range.InsertParagraphAfter(); } else { ParameterizedString parametrizedString = new ParameterizedString(((ITestStep)testCase.ElementAt(Index).Actions[i]).Title.ToPlainText()); // Добавить текст Action на второй уровень нумерованного многоуровневого списка paragraph.Range.Text = get_ActionWithParameters(testCase.ElementAt(Index), parametrizedString.ToPlainText()); paragraph.Range.SetListLevel(2); paragraph.Range.ListFormat.ApplyListTemplateWithLevel(listTemplate, ContinuePreviousList: true, ApplyTo: WdListApplyTo.wdListApplyToSelection, DefaultListBehavior: WdDefaultListBehavior.wdWord10ListBehavior, ApplyLevel: 2); paragraph.Range.InsertParagraphAfter(); } } }
private void FinishTestStep(TestOutcome testOutcome = TestOutcome.Passed) { if (CurrentlyInSharedStep()) { _currentTestStepResult.Outcome = testOutcome; _currentSharedTestStepResult.Actions.Add(_currentTestStepResult); if (!HasMoreSharedSteps() || (testOutcome == TestOutcome.Failed || testOutcome == TestOutcome.Error)) { CloseSharedStep(testOutcome); _currentSharedStep = null; _currentSharedSteps = new List <ITestAction>(); } } else { SetTestStepResultAndSaveToIteration(_currentTestStepResult, testOutcome); } }
public static void AddE2ESteps(SharedStepsObject sharedStepsObject, int testCaseId) { TfsTeamProjectCollection tfs; tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(sharedStepsObject.uri)); tfs.Authenticate(); ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService)); ITestManagementTeamProject testProject = service.GetTeamProject(sharedStepsObject.project); ITestCase testCase = testProject.TestCases.Find(testCaseId); foreach (string step in sharedStepsObject.actionSteps) { int sharedStepId = GetsharedStepId(step, sharedStepsObject); ISharedStepReference sharedStepReference = testCase.CreateSharedStepReference(); sharedStepReference.SharedStepId = sharedStepId; testCase.Actions.Add(sharedStepReference); } testCase.Save(); }
public static void AddTestCaseSteps(SharedStepsObject sharedStepsObject, int testCaseId) { TfsTeamProjectCollection tfs; tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(sharedStepsObject.uri)); tfs.Authenticate(); ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService)); ITestManagementTeamProject testProject = service.GetTeamProject(sharedStepsObject.project); ITestCase testCase = testProject.TestCases.Find(testCaseId); ISharedStepReference sharedStepReference = testCase.CreateSharedStepReference(); int sharedStepId = sharedStepsObject.id; sharedStepReference.SharedStepId = sharedStepId; testCase.Actions.Add(sharedStepReference); if (sharedStepsObject.automationValue.ToString() != "") { testCase.CustomFields["Automation Status1"].Value = sharedStepsObject.automationValue.ToString(); //"Planned"; } testCase.Save(); }
/// <summary> /// Gets the test steps from test actions. /// </summary> /// <param name="testActions">The test actions.</param> /// <param name="alreadyAddedSharedSteps">The already added shared steps.</param> /// <param name="sharedSteps">The shared steps.</param> /// <returns>list of all test steps</returns> public static List <TestStep> GetTestStepsFromTestActions(ITestManagementTeamProject testManagementTeamProject, ICollection <ITestAction> testActions) { List <TestStep> testSteps = new List <TestStep>(); foreach (var currentAction in testActions) { if (currentAction is ITestStep) { Guid testStepGuid = Guid.NewGuid(); testSteps.Add(new TestStep(false, string.Empty, testStepGuid, currentAction as ITestStep)); } else if (currentAction is ISharedStepReference) { ISharedStepReference currentSharedStepReference = currentAction as ISharedStepReference; ISharedStep currentSharedStep = testManagementTeamProject.SharedSteps.Find(currentSharedStepReference.SharedStepId); testSteps.AddRange(TestStepManager.GetAllTestStepsInSharedStep(currentSharedStep)); } } return(testSteps); }
private void TestCaseInfoForm_Load(object sender, EventArgs e) { try { label1.Text = testCase.ElementAt(nToolTipIndex).Title; ISharedStep sharedStep = null; ISharedStepReference sharedStepReference = null; List <string> actionsList = new List <string>(); if (testCase.ElementAt(nToolTipIndex).Actions.Count == 0) { actionsList.Add("Тест кейс пуст"); } for (int i = 0; i < testCase.ElementAt(nToolTipIndex).Actions.Count; i++) { sharedStepReference = testCase.ElementAt(nToolTipIndex).Actions.ElementAt(i) as ISharedStepReference; if (sharedStepReference != null) { sharedStep = sharedStepReference.FindSharedStep(); actionsList.Add((i + 1) + ". " + sharedStep.Title + "\t(ОБЩИЙ ШАГ)"); } else { ParameterizedString parametrizedString = new ParameterizedString(((ITestStep)testCase.ElementAt(nToolTipIndex).Actions[i]).Title.ToPlainText()); actionsList.Add((i + 1) + ". " + wordFile.get_ActionWithParameters(testCase.ElementAt(nToolTipIndex), parametrizedString.ToPlainText())); } } listBox1.Items.AddRange(actionsList.ToArray()); } catch { listBox1.Items.Add("В запросе отсутствуют тест кейсы."); } }
/// <summary> /// Finds all reference test cases for specific shared step. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="sharedStepId">The shared step unique identifier.</param> /// <returns></returns> public static List <TestCase> FindAllReferenceTestCasesForShareStep(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int sharedStepId) { List <TestCase> filteredTestCases = new List <TestCase>(); List <TestCase> allTestCases = GetAllTestCasesInTestPlan(testManagementTeamProject, testPlan); foreach (var currentTestCase in allTestCases) { foreach (var currentAction in currentTestCase.ITestCase.Actions) { if (currentAction is ISharedStepReference) { ISharedStepReference currentSharedStepReference = currentAction as ISharedStepReference; if (currentSharedStepReference.SharedStepId.Equals(sharedStepId)) { filteredTestCases.Add(currentTestCase); break; } } } } return(filteredTestCases); }
private int GenerateTestCase(ITestSuiteEntry testCaseEntry, int startRow) { int currentRowNumber = this.GenerateTestCaseHeader(startRow, testCaseEntry); int startingRowNumber = currentRowNumber; int stepNumber = 1; foreach (ITestAction action in testCaseEntry.TestCase.Actions) { if (action is ISharedStepReference) { ISharedStepReference isr = (ISharedStepReference)action; ISharedStep ss = isr.FindSharedStep(); TestActionCollection sharedActions = ss.Actions; foreach (ITestAction sharedAction in sharedActions) { GenereateTestStepRow(currentRowNumber, stepNumber, (ITestStep)sharedAction); stepNumber++; currentRowNumber++; } } else { GenereateTestStepRow(currentRowNumber, stepNumber, (ITestStep)action); stepNumber++; currentRowNumber++; } } int endingRowNumber = currentRowNumber - 1; _range = _worksheet.get_Range("B" + startingRowNumber, (RefinementWindow.createComments ? "E" : "D") + endingRowNumber); DrawAllSolidBorders(_range, 0); return(currentRowNumber + 1); }
/// <summary> /// Migrate Test Cases from source to target project /// </summary> private void MigrateTestCases() { int testCaseCount = 0; int testCaseFailures = 0; Trace.WriteLine($"** Starting Test Case Migration: {DateTime.Now.ToLongTimeString()}"); Stopwatch sw = new Stopwatch(); sw.Start(); var testCaseQuery = $"SELECT * FROM WorkItems WHERE [Work Item Type] = 'Test Case' AND [Team Project] = '{sourceProjectName}'"; IEnumerable <ITestCase> testCases = tmSourceProject.TestCases.Query(testCaseQuery); foreach (var sourceTestCase in testCases) { try { testCaseCount++; synchronizationContext.Post(UpdateStatus, $"Processing test case {testCaseCount} ({testCaseFailures})"); Trace.WriteLine(String.Format("Test Case {0}: {1}", sourceTestCase.Id, sourceTestCase.Title)); var targetTestCase = new WorkItem(wisTargetProject.Projects[targetProjectName].WorkItemTypes["Test Case"]); targetTestCase.Title = sourceTestCase.Title; targetTestCase.Description = sourceTestCase.Description; targetTestCase["Priority"] = sourceTestCase.Priority; targetTestCase.IterationPath = sourceTestCase.WorkItem.IterationPath.Replace(sourceProjectName, targetProjectName); targetTestCase.AreaPath = sourceTestCase.WorkItem.AreaPath.Replace(sourceProjectName, targetProjectName); targetTestCase.State = sourceTestCase.State; targetTestCase[CoreField.AssignedTo] = GetUser(sourceTestCase.WorkItem[CoreField.AssignedTo] as string); targetTestCase.Tags = sourceTestCase.WorkItem.Tags; // TODO: Create ReflectedWorkitemId field on TestCase work item type in VSTS targetTestCase["ReflectedWorkitemId"] = targetUri + sourceTestCase.Id; // TODO: Add any custom fields here. //targetTestCase["Precondition"] = sourceTestCase.CustomFields["Pre Condition"].Value; targetTestCase.Save(); var targetTestCaseQuery = $"SELECT * FROM WorkItems WHERE [Work Item Type] = 'Test Case' AND [Id] = {targetTestCase.Id}"; var testCase = tmTargetProject.TestCases.Query(targetTestCaseQuery).FirstOrDefault(); testCase.WorkItem.Open(); foreach (var action in sourceTestCase.Actions) { ITestStep step = action as ITestStep; if (step != null) { Trace.WriteLine($"\tStep {step.Id}: Title = {step.Title}, ExpectedResult = {step.ExpectedResult}"); var targetTestStep = testCase.CreateTestStep(); targetTestStep.Title = step.Title; targetTestStep.ExpectedResult = step.ExpectedResult; testCase.Actions.Add(targetTestStep); } else { // Since this was not a regular test step, assume Shared Step ISharedStepReference sourceSharedStep = action as ISharedStepReference; if (sourceSharedStep != null) { Trace.WriteLine(String.Format("\tShared Step Reference: {0}", sourceSharedStep.Id)); var targetSharedStep = testCase.CreateSharedStepReference(); int mappedId = 0; sharedStepMapping.TryGetValue(sourceSharedStep.SharedStepId, out mappedId); if (mappedId != 0) { targetSharedStep.SharedStepId = mappedId; testCase.Actions.Add(targetSharedStep); } else { var targetTestStep = testCase.CreateTestStep(); targetTestStep.Title = $"PLACEHOLDER: Shared Step (original ID:{sourceSharedStep.SharedStepId}"; testCase.Actions.Add(targetTestStep); } } } } testCase.Save(); } catch (Exception ex) { testCaseFailures++; Trace.WriteLine($"Error processing test case ({sourceTestCase.Id}:{sourceTestCase.Title}): {ex.Message}"); } } sw.Stop(); Trace.WriteLine($"** Test Case Migration Complete: {DateTime.Now.ToLongTimeString()}"); Trace.WriteLine($"** Successfully migrated {testCaseCount - testCaseFailures} of {testCaseCount} test cases"); Trace.WriteLine($"** Execution time {sw.Elapsed.TotalSeconds} seconds"); synchronizationContext.Post(UpdateStatus, $"Processing test case {testCaseCount} ({testCaseFailures}). PROCESSING COMPLETE."); }
/// <summary> /// Saves the specified test case. /// </summary> /// <param name="sourceTestCase">The test case.</param> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="createNew">should be saved as new test case.</param> /// <param name="suiteId">The suite identifier.</param> /// <param name="testSteps">The test steps.</param> /// <param name="shouldAssignArea">if set to <c>true</c> [should assign area].</param> /// <param name="isMigration">if set to <c>true</c> [is migration].</param> /// <returns> /// the saved test case /// </returns> public static TestCase Save( this TestCase sourceTestCase, ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, bool createNew, int?suiteId, ICollection <TestStep> testSteps, bool shouldAssignArea = true, bool isMigration = false) { TestCase currentTestCase = sourceTestCase; if (createNew) { ITestCase testCaseCore = testManagementTeamProject.TestCases.Create(); currentTestCase = new TestCase(testCaseCore, sourceTestCase.ITestSuiteBase, testPlan); } if (shouldAssignArea) { currentTestCase.ITestCase.Area = sourceTestCase.Area; } currentTestCase.ITestCase.Description = sourceTestCase.ITestCase.Description; currentTestCase.ITestCase.Title = sourceTestCase.Title; currentTestCase.ITestCase.Priority = (int)sourceTestCase.Priority; currentTestCase.ITestCase.Actions.Clear(); currentTestCase.ITestCase.Owner = testManagementTeamProject.TfsIdentityStore.FindByTeamFoundationId(sourceTestCase.TeamFoundationId); if (sourceTestCase.ITestCase.Implementation != null && isMigration) { currentTestCase.ITestCase.Implementation = sourceTestCase.ITestCase.Implementation; } List <Guid> addedSharedStepGuids = new List <Guid>(); foreach (TestStep currentStep in testSteps) { if (currentStep.IsShared && !addedSharedStepGuids.Contains(currentStep.TestStepGuid)) { ISharedStep sharedStepCore = testManagementTeamProject.SharedSteps.Find(currentStep.SharedStepId); ISharedStepReference sharedStepReferenceCore = currentTestCase.ITestCase.CreateSharedStepReference(); sharedStepReferenceCore.SharedStepId = sharedStepCore.Id; currentTestCase.ITestCase.Actions.Add(sharedStepReferenceCore); addedSharedStepGuids.Add(currentStep.TestStepGuid); } else if (!currentStep.IsShared) { ITestStep testStepCore = currentTestCase.ITestCase.CreateTestStep(); testStepCore.Title = currentStep.ActionTitle; testStepCore.ExpectedResult = currentStep.ActionExpectedResult; currentTestCase.ITestCase.Actions.Add(testStepCore); } } if (suiteId != null) { var newSuite = TestSuiteManager.GetTestSuiteById(testManagementTeamProject, testPlan, (int)suiteId); sourceTestCase.ITestSuiteBase = newSuite; } currentTestCase.ITestCase.Flush(); currentTestCase.ITestCase.Save(); if (suiteId != null) { SetTestCaseSuite(testManagementTeamProject, testPlan, (int)suiteId, currentTestCase); } currentTestCase.ITestCase.Flush(); currentTestCase.ITestCase.Save(); return(currentTestCase); }
private ITestActionResult CreateSharedStepResult(ISharedStepReference testStep) { return(_iteration.CreateSharedStepResult(testStep.Id, testStep.FindSharedStep().Id)); }